This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Guile's threads and mutex


Hi,

Guiles documentation says about mutex:

 - primitive: unlock-mutex MUTEX
     Unlocks MUTEX if the calling thread owns the lock on MUTEX.
     Calling unlock-mutex on a mutex not owned by the current thread
     results in undefined behaviour. Once a mutex has been unlocked,
     one thread blocked on MUTEX is awakened and grabs the mutex lock.

When I understand this right, it means, that I can not use a mutex for
flow control between two threads.

I have two threads A and B and a queue, which can be written to by
thread A (and also by some other threads) and read from by thread
B. Thread B should block, when the queue is empty. When I want to use
a emtpy-mutex, it must be locked by the init thread, which creates the
mutex, because in the beginning the queue is empty. By reading the
queue thread B blocks. But it is not possible to unlock the
empty-mutex, because it is likely that the thread writing to the queue
is not the thread, who created the mutex.

How can I get such a "select" functionality for Guile threads?

-- 
http://www.ping.de/sites/aibon/