Locking allows different types of resources to be used exclusively by one process at a time.

398
votes
14answers
134k views

Why is lock(this) {…} bad?

The MSDN documentation says thatpublic class SomeObject{public void SomeOperation(){lock(this){//Access instance variables}}}is "a problem if the instance can be ...
62
votes
7answers
27k views

Only inserting a row if it's not already there

I had always used something similar to the following to achieve it:INSERT INTO TheTableSELECT@primaryKey,@value1,@value2WHERENOT EXISTS(SELECTNULLFROM...
341
votes
8answers
213k views

Optimistic vs. Pessimistic locking

I understand the differences between optimistic and pessimistic locking*. Now could someone explain to me when I would use either one in general?And does the answer to this question change ...
568
votes
9answers
105k views

Volatile vs. Interlocked vs. lock

Let's say that a class has a public int counter field that is accessed by multiple threads. This int is only incremented or decremented.To increment this field, which approach should be used, and ...
107
votes
8answers
154k views

Any way to select without causing locking in MySQL?

Query:SELECT COUNT(online.account_id) cnt from online;But online table is also modified by an event, so frequently I can see lock by running show processlist.Is there any grammar in MySQL that ...
72
votes
17answers
128k views

How to disable Home and other system buttons in Android?

I need to disable Home and other system buttons in my Android application.Example: MX Player (see at Google Play) - you can press "lock" icon at player screen and it locks all hardware and software ...
22
votes
4answers
29k views

Lock the android device programmatically

I have been trying to lock the device through program. But I can't find the solution still.I want to lock android froyo2.2 through program. I have tried keyguardmanager and DeviceAdminManager.My ...
43
votes
6answers
16k views

Why is volatile used in this example of double checked locking

From Head First design patterns book, the singleton pattern with double checked locking has been implemented as below: public class Singleton {private volatile static Singleton instance;...
23
votes
1answer
17k views

Locking the Fields in MFMailComposeViewController

Is it possible to somehow lock the fields in an MFMailComposeViewController so that the body, recipients etc cannot be changed by the user? I need the e-mail the user sends to go to a particular ...
26
votes
10answers
32k views

Lock Unlock events iphone

How can I detect lock/unlock events on the iPhone? Assuming it's only possible for jailbroken devices, can you point me to the correct API?By lock events, I mean showing or hiding the Lock Screen (...
175
votes
5answers
25k views

Do spurious wakeups actually happen?

Seeing various locking related question and (almost) always finding the 'loop because of spurious wakeups' terms1 I wonder, has anyone experienced such kind of a wakeup (assuming a decent hardware/...
347
votes
8answers
198k views

How does lock work exactly?

I see that for using objects which are not thread safe we wrap the code with a lock like this:private static readonly Object obj=new Object();lock (obj){// thread unsafe code}So what ...
152
votes
6answers
97k views

Recursive Lock (Mutex) vs Non-Recursive Lock (Mutex)

POSIX allows mutexes to be recursive. That means the same thread can lock the same mutex twice and won't deadlock. Of course it also needs to unlock it twice, otherwise no other thread can obtain the ...
88
votes
17answers
45k views

Python: single instance of program

Is there a Pythonic way to have only one instance of a program running? The only reasonable solution I've come up with is trying to run it as a server on some port, then second program trying to ...
59
votes
12answers
62k views

Reader/Writer Locks in C++

I'm looking for a good reader/writer lock in C++. We have a use case of a single infrequent writer and many frequent readers and would like to optimize for this. Preferable I would like a cross-...

153050per page
angop.ao, elkhabar.com, noa.al, afghanpaper.com, bbc.com, time.com, cdc.gov, nih.gov, xnxx.com, github.com,