manuel-serrano / bigloo

a practical Scheme compiler
http://www-sop.inria.fr/indes/fp/Bigloo
Other
133 stars 20 forks source link

condvar and mutex fixes for Pthread and SRFI18 #111

Closed donaldsonjw closed 6 months ago

donaldsonjw commented 6 months ago

updated the bglpcondvar and jcondvar classes to correctly handle timed waits. The old implementation used a list to record timed waiting threads and removed the head of that list upon notify (or all threads for notifyAll). However, when multiple threads are waiting on a condition variable, there is no guarantee that the first notified is the first to have waited. This can result in removing a still waiting thread from the list and potentially causing the awoken thread to believe its wait has timed out. The new implementation is modeled on the Timed Waits described in Doug Lea's Concurrent Programming in Java 2nd Edition pages 194-195 and his original implementation of condvars in the EDU.oswego.cs.dl.util.concurrent.CondVar class.

The bglpmutex and jmutex classes were also updated to remove a race condition in updating the owning thread and mutex state that could occurr between 1 thread unlocking the mutex and another locking the mutex.