Reader/Writer Locks in C++

Since C++ 17 (VS2015) you can use the standard: #include <shared_mutex> typedef std::shared_mutex Lock; typedef std::unique_lock< Lock > WriteLock; typedef std::shared_lock< Lock > ReadLock; Lock myLock; void ReadFunction() { ReadLock r_lock(myLock); //Do reader stuff } void WriteFunction() { WriteLock w_lock(myLock); //Do writer stuff } For older compiler versions and standards you can use boost to … Read more

Python sharing a lock between processes

You can’t pass normal multiprocessing.Lock objects to Pool methods, because they can’t be pickled. There are two ways to get around this. One is to create Manager() and pass a Manager.Lock(): def main(): iterable = [1, 2, 3, 4, 5] pool = multiprocessing.Pool() m = multiprocessing.Manager() l = m.Lock() func = partial(target, l) pool.map(func, iterable) … Read more

Are locks unnecessary in multi-threaded Python code because of the GIL?

You will still need locks if you share state between threads. The GIL only protects the interpreter internally. You can still have inconsistent updates in your own code. For example: #!/usr/bin/env python import threading shared_balance = 0 class Deposit(threading.Thread): def run(self): for _ in xrange(1000000): global shared_balance balance = shared_balance balance += 100 shared_balance = … Read more

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