no uzerver responding to Jk wrote:It cannot even be done, as your assumptions are totally wrong. Mutexes simply do not work like that. Threads that want to lock a mutex end up waiting in a queue-like fasion and will begin running immediately once the lock is released.
From class mutex boost documentation:
Ok so pthreads on linux and pthreads on mingw.If boost has detected thread support in your compiler, the mutex class will map to a CRITICAL_SECTION on Windows or a pthread_mutex on POSIX.
From POSIX spec page on
pthread.h / pthread_mutex_lock:
This guy has something on scheduling policy (section named "5 Linux" is about pthread):If there are threads blocked on the mutex object referenced by mutex when pthread_mutex_unlock() is called, resulting in the mutex becoming available, the scheduling policy shall determine which thread shall acquire the mutex.
Which i suppose means using theThe default scheduling policy is SCHED_OTHER, which is the default Linux scheduler.
traditional scheduling (look at the "absolute scheduling as Roman cultural invasion" analogy WTF)
So basically boost and other pthread mutex rehashes behaviour is defined as LOL SO RANDUMBThe dynamic priority sometimes determines who gets the next turn on the CPU. Sometimes it determines how long turns last. Sometimes it determines whether a process can kick another off the CPU.
and if two threads try acquiring and releasing mutexes as fast as possible it is practically guaranteed that they will go out of order especially with other OS processes or threads running and screwing the scheduling.
You can ofcourse use some cheesy mutex implementation like with a synchronized queue.
Code: Select all
on lock:
if queue is empty: insert thread into queue & go
if queue is not empty: insert thread & wait until the thread is in 1st position in queue then go
on unlock:
remove 1st position from queue
(actually i think Jk's set-a-bit-when-waiting thing behaviour is same as this in case threre only 2 threads)
but instead of render thread thread being able to go through multiple times in a row access will be interleaved.
Over 396 Ewoks died to bring you this information.
Also clearly we shouldbeable to post in the dedicated dev forum, cleaning it up from spam would then distract neddie from writing random flame posts, forum policies and thread lockings thushaving an effect infinetimally superior to say the global moderator nomination thread.
Also i ran out of space for thread subject 60 chars is way too little ;_;