www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - On sychronized(lock1, lock2, ...)

reply Ruby The Roobster <rubytheroobster yandex.com> writes:
This is a "feature" mentioned in Ali's book, with the note that 
it isn't currently supported.  Is there any chance of this being 
implemented along the model of if deadlock, give all locks to the 
thread with the lowest Tid until unlock, then pass the lock to 
the thread with the next-highest Tid, and so on and so forth.
Aug 10 2022
parent =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 8/10/22 19:18, Ruby The Roobster wrote:
 give all locks to the thread with the
 lowest Tid until unlock, then pass the lock to the thread with the
 next-highest Tid, and so on and so forth.
I thought, as long as all threads use the same order when locking, there would be no deadlock (at least for this critical section). The locks can be sorted by their memory addresses. But I can see how that can fail if one of the "later" locks is already locked by one of the threads. I am not an expert on this; trying to learn... Ali
Aug 10 2022