What’s the difference between an exclusive lock and a shared lock?

I wrote this answer down because I thought this would be a fun (and fitting) analogy: Think of a lockable object as a blackboard (lockable) in a class room containing a teacher (writer) and many students (readers). While a teacher is writing something (exclusive lock) on the board: Nobody can read it, because it’s still … Read more

Make sure only a single instance of a program is running

The following code should do the job, it is cross-platform and runs on Python 2.4-3.2. I tested it on Windows, OS X and Linux. from tendo import singleton me = singleton.SingleInstance() # will sys.exit(-1) if other instance is running The latest code version is available singleton.py. Please file bugs here. You can install tend using … Read more

Any way to select without causing locking in MySQL?

Found an article titled “MYSQL WITH NOLOCK” https://web.archive.org/web/20100814144042/http://sqldba.org/articles/22-mysql-with-nolock.aspx in MS SQL Server you would do the following: SELECT * FROM TABLE_NAME WITH (nolock) and the MYSQL equivalent is SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED ; SELECT * FROM TABLE_NAME ; SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ ; EDIT Michael Mior suggested the following … Read more

What are the differences between various threading synchronization options in C#?

Great question. I maybe wrong.. Let me try.. Revision#2 of my orig answer.. with a little bit of more understanding. Thanks for making me read 🙂 lock(obj) is a CLR construct that for (intra-object?) thread synchronization. Ensures that only one thread can take ownership of the object’s lock & enter the locked block of code. … Read more

How efficient is locking and unlocked mutex? What is the cost of a mutex?

I have the choice in between either having a bunch of mutexes or a single one for an object. If you have many threads and the access to the object happens often, then multiple locks would increase parallelism. At the cost of maintainability, since more locking means more debugging of the locking. How efficient is … Read more

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

The difference between a recursive and non-recursive mutex has to do with ownership. In the case of a recursive mutex, the kernel has to keep track of the thread who actually obtained the mutex the first time around so that it can detect the difference between recursion vs. a different thread that should block instead. … Read more

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