Read Locks and Write Locks

In database management theory, locking is used to implement isolation among multiple database users txn. This is the “I” in the acronym ACID (Atomicity, Consistency, Isolation, Durability). Locks are applied by a TX (transaction) to data, which may block other TXs from accessing the same data during the TX’s life. Simple Locking: Two main types … Read more

Do I need to lock or mark as volatile when accessing a simple boolean flag in C#?

Firstly, threading is tricky ;-p Yes, despite all the rumours to the contrary, it is required to either use lock or volatile (but not both) when accessing a bool from multiple threads. For simple types and access such as an exit flag (bool), then volatile is sufficient – this ensures that threads don’t cache the … Read more

Is it OK to use a string as a lock object?

Locking on strings is discouraged, the main reason is that (because of string-interning) some other code could lock on the same string instance without you knowing this. Creating a potential for deadlock situations. Now this is probably a far fetched scenario in most concrete situations. It’s more a general rule for libraries. But on the … Read more

How would you implement your own reader/writer lock in C++11?

Here’s pseudo-code for a ver simply reader/writer lock using a mutex and a condition variable. The mutex API should be self-explanatory. Condition variables are assumed to have a member wait(Mutex&) which (atomically!) drops the mutex and waits for the condition to be signaled. The condition is signaled with either signal() which wakes up one waiter, … Read more

What is lock-free multithreaded programming?

The key in lock-free programming is to use hardware-intrinsic atomic operations. As a matter of fact, even locks themselves must use those atomic operations! But the difference between locked and lock-free programming is that a lock-free program can never be stalled entirely by any single thread. By contrast, if in a locking program one thread … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)