ReentrantReadWriteLock: what’s the difference between ReadLock and WriteLock?

readLock.lock(); This means that if any other thread is writing (i.e. holds a write lock) then stop here until no other thread is writing. Once the lock is granted no other thread will be allowed to write (i.e. take a write lock) until the lock is released. writeLock.lock(); This means that if any other thread … Read more

Difference between manual locking and Synchronized methods

The first method is preferred because you can (and should) make _syncRoot private. This lowers the risk of deadlocking. The MethodImplOptions.Synchronized is a left-over from an earlier ambitious idea that turned out to be not so good after all. Regarding the last question: Yes, according to this blog they are functionally equivalent (but not implemented … Read more

Pure-Ruby concurrent Hash

Okay, now that you specified the actually meaning of ‘threadsafe’, here are two potential implementations. The following code will run forever in MRI and JRuby. The lockless implementation follows an eventual consistency model where each thread uses it’s own view of the hash if the master is in flux. There is a little trickery required … Read more

C# thread safety with get/set

No, your code won’t lock access to the members of the object returned from MyProperty. It only locks MyProperty itself. Your example usage is really two operations rolled into one, roughly equivalent to this: // object is locked and then immediately released in the MyProperty getter MyObject o = MyProperty; // this assignment isn’t covered … Read more

What is (are) difference between NOLOCK and UNCOMMITTED

NOLOCK : Is equivalent to READ UNCOMMITTED (source : MSDN) NOLOCK or READ UNCOMMITTED Specifies that dirty reads are allowed. No shared locks are issued to prevent other transactions from modifying data read by the current transaction, and exclusive locks set by other transactions do not block the current transaction from reading the locked data. … Read more

boost::unique_lock vs boost::lock_guard

First to answer your question. No you don’t need to call lock on a unique_lock. See below: The unique_lock is only a lock class with more features. In most cases the lock_guard will do what you want and will be sufficient. The unique_lock has more features to offer to you. E.g a timed wait if … Read more

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