digitalmars.D.learn - Producer/Consumer Queue in D
- Jeff (6/6) Jan 24 2006 I'm trying to learn how to do thread synchonization in D without waitabl...
- Sean Kelly (12/18) Jan 24 2006 On non-Windows systems, the classic approach is to use a condition
I'm trying to learn how to do thread synchonization in D without waitable objects like semaphores. For example, how would you implement the classic multi-threaded producer/consumer queue? Where the consumer threads wait (zero cpu) until there is an element inserted into the queue? -Jeff
Jan 24 2006
Jeff wrote:I'm trying to learn how to do thread synchonization in D without waitable objects like semaphores. For example, how would you implement the classic multi-threaded producer/consumer queue? Where the consumer threads wait (zero cpu) until there is an element inserted into the queue?On non-Windows systems, the classic approach is to use a condition variable, which is basically a fancy semaphore. On Windows systems, an event is typically used instead, though as events are somewhat broken this can be problematic if there are multiple competing consumers. But waiting isn't required in either case, as it's possible to test the variable or event without blocking. If you're aiming for truly lock-free code, look around for a lock-free slist. A low-level implementation is included with Visual Studio, and there are a number of open source versions available (though I don't have a link to one at the moment). Sean
Jan 24 2006