How to easily make std::cout thread-safe?

While I can’t be sure this applies to every compiler / version of std libs but in the code-base I’m using std::cout::operator<<() it is already thread-safe. I’m assuming that what you’re really trying to do it stop std::cout from mixing string when concatenating with the operator<< multiple time per string, across multiple threads. The reason … Read more

Throw a NullReferenceException while calling the set_item method of a Dictionary object in a multi-threading scenario

As the exception occurs internally in the Dictionary code, it means that you are accessing the same Dictionary instance from more than one thread at the same time. You need to synchronise the code in the GetInstance method so that only one thread at a time accesses the Dictionary. Edit: Lock around the accesses separately, … Read more

What is the difference between synchronized on lockObject and using this as the lock?

Personally I almost never lock on “this”. I usually lock on a privately held reference which I know that no other code is going to lock on. If you lock on “this” then any other code which knows about your object might choose to lock on it. While it’s unlikely to happen, it certainly could … Read more

How to find out what is locking my tables?

Take a look at the following system stored procedures, which you can run in SQLServer Management Studio (SSMS): sp_who sp_lock Also, in SSMS, you can view locks and processes in different ways: Different versions of SSMS put the activity monitor in different places. For example, SSMS 2008 and 2012 have it in the context menu … Read more

What is the difference between a lock and a latch in the context of concurrent access to a database?

From CMU 15-721 (Spring 2016), lecture 6 presentation, slides 25 and 26, which cites A Survey of B-Tree Locking Techniques by Goetz Graefe: Locks → Protects the index’s logical contents from other txns. → Held for txn duration. → Need to be able to rollback changes. Latches → Protects the critical sections of the index’s … Read more

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