locking

What's the default lock granularity in SQL Server?

女生的网名这么多〃 提交于 2019-12-01 16:25:28
问题 I've thoroughly read MSDN about table hints and I don't seem to find the locking granularity default. Suppose I have the following query: SELECT TOP (1) * FROM MyTable WITH (UPDLOCK, READPAST) ORDER BY SomeColumn ASC; You see, I specified UPDLOCK and READPAST hints, but not any of granularity hints such as TABLOCK or ROWLOCK . Which granularity lock level is used by default? 回答1: There is no 'default'. The granularity (row, page, (partition | object)) is computed dynamically based on allowed

Does a getter function need a mutex?

若如初见. 提交于 2019-12-01 16:19:57
I have a class that is accessed from multiple threads. Both of its getter and setter functions are guarded with locks. Are the locks for the getter functions really needed? If so, why? class foo { public: void setCount (int count) { boost::lock_guard<boost::mutex> lg(mutex_); count_ = count; } int count () { boost::lock_guard<boost::mutex> lg(mutex_); // mutex needed? return count_; } private: boost::mutex mutex_; int count_; }; The only way you can get around having the lock is if you can convince yourself that the system will transfer the guarded variable atomicly in all cases. If you can't

“error code 5: database is locked” when using a ContentProvider

╄→尐↘猪︶ㄣ 提交于 2019-12-01 16:15:46
问题 I have an application that runs an activity with a service in a separate process that is started and bound to the activity. The service contains a handler that posts a runnable to be run after a delay. I want each component to log to the database, so I implemented a content provider that deals with database access and I call it from the service or activity via extended AsyncTask sub-classes. This all works beautifully on the emulator, but when I run it in debug on my phone I get a sporadic

Does Apache read-lock files before serving them?

巧了我就是萌 提交于 2019-12-01 15:39:00
问题 I have an mobile app that reads a JSON file that is stored on an Apache server. The contents of that JSON file are regenerated (using a PHP script) if something is changed via a GUI. I am worried that trying to overwrite the JSON file in the middle of it being served by Apache might cause problems. Does Apache obtain a read lock before serving files? If not, what will happen if I try to write it at the same time it is being served? 回答1: No. On POSIX-compatible systems, all locks are advisory

Why doesn't C# allow a null value to be locked?

谁都会走 提交于 2019-12-01 15:34:58
C# doesn't allow locking on a null value. I suppose I could check whether the value is null or not before I lock it, but because I haven't locked it another thread could come along and make the value null! How can I avoid this race condition? Chris Shain Lock on a value that is never null, e.g. Object _lockOnMe = new Object(); Object _iMightBeNull; public void DoSomeKungFu() { if (_iMightBeNull == null) { lock (_lockOnMe) { if (_iMightBeNull == null) { _iMightBeNull = ... whatever ...; } } } } Also be careful to avoid this interesting race condition with double-checked locking: Memory Model

Safe to get Count value from generic collection without locking the collection?

最后都变了- 提交于 2019-12-01 15:33:35
I have two threads, a producer thread that places objects into a generic List collection and a consumer thread that pulls those objects out of the same generic List. I've got the reads and writes to the collection properly synchronized using the lock keyword, and everything is working fine. What I want to know is if it is ok to access the Count property without first locking the collection. JaredPar refers to the Count property in his blog as a decision procedure that can lead to race conditions, like this: if (list.Count > 0) { return list[0]; } If the list has one item and that item is

PSQLException and lock issue when trigger added on table

柔情痞子 提交于 2019-12-01 15:20:47
UPDATE: I eliminated Hibernate from the problem. I completely reworked description of problem to simplify it as much as possible. I have master table with noop trigger and detail table with two relations between master and detail table: create table detail ( id bigint not null, code varchar(255) not null, primary key (id) ); create table master ( id bigint not null, name varchar(255), detail_id bigint, -- "preferred" detail is one-to-one relation primary key (id), unique (detail_id), foreign key (detail_id) references detail(id) ); create table detail_candidate ( -- "candidate" details = many

Safe to get Count value from generic collection without locking the collection?

感情迁移 提交于 2019-12-01 14:31:12
问题 I have two threads, a producer thread that places objects into a generic List collection and a consumer thread that pulls those objects out of the same generic List. I've got the reads and writes to the collection properly synchronized using the lock keyword, and everything is working fine. What I want to know is if it is ok to access the Count property without first locking the collection. JaredPar refers to the Count property in his blog as a decision procedure that can lead to race

Does a getter function need a mutex?

笑着哭i 提交于 2019-12-01 14:18:51
问题 I have a class that is accessed from multiple threads. Both of its getter and setter functions are guarded with locks. Are the locks for the getter functions really needed? If so, why? class foo { public: void setCount (int count) { boost::lock_guard<boost::mutex> lg(mutex_); count_ = count; } int count () { boost::lock_guard<boost::mutex> lg(mutex_); // mutex needed? return count_; } private: boost::mutex mutex_; int count_; }; 回答1: The only way you can get around having the lock is if you

how to lock the android programatically

扶醉桌前 提交于 2019-12-01 14:05:16
i want to lock the phone when i click the lock button.anybody please help with simple code.i tried with part of code from API_Demos but it shows some error. You can lock the Android's screen programmatically using the LockScreen class like so: KeyguardManager mgr = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE); KeyguardLock lock = mgr.newKeyguardLock(KEYGUARD_SERVICE); lock.reenableKeyguard(); Take a look at the LockScreen class here . The code: KeyguardManager mgr = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE); KeyguardLock lock = mgr.newKeyguardLock(KEYGUARD