Hi guys,

I've been working on fixing some dead locks that were occurring once in a 
while. The problem was that threads were restarted while holding mutex 
lock(s), which inevitably leads to dead locks even if the thread resumes later 
on.

To address this, I changed the way all thread loops work in LS, which 
basically is now:

int SomeThread::Main() {
        while (true) {
                // custom & safe cancellation point for thread
                TestCancel();

                // prevent thread from being cancelled
                // (e.g. to prevent deadlocks while holding a mutex lock)
                pushCanelable(false);

                // enter critical section involving locks and syscalls, e.g.:
                mutex.Lock();
                doSomeWork();
                usleep(100); //NOTE: defined as cancellation point by POSIX!
                mutex.Unlock();

                // now allow thread being cancelled again
                popCancelable();
        }
}

So threads use now "well defined", safe cancellation points. Accordingly the 
code base now relies on pthread_testcancel() being available, and if it is 
avilable then threads are no longer created as being asynchronously 
cancellable.

Since this meant quite a bunch of sensible changes, please let me know if 
things start to hang somewhere!

CU
Christian




_______________________________________________
Linuxsampler-devel mailing list
Linuxsampler-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxsampler-devel

Reply via email to