Thank you for your reply.
I have some more questions:
I simplified my example. Now my monitor is used for mutual
exclusion, to understand how monitors work first.
// 3 threads are running P() - the main thread is not one of them
void P()
{
while( run )
{
monit
You need to lock the mutex to synchronize access to the shared data.
On Jul 27, 2012, at 2:31 PM, Minas Mina wrote:
>
> class Monitor
> {
> Cond cond;
Mutex mutex;
>
> char[] buffer;
> ulong sz;
>
> this()
> {
> // necessary:
I'm using condition variables to implement a monitor that
simulates the producer-consumer(unbounded buffer) scenario.
Note:
monitor is __gshared and is initialized in main(). Then the other
threads are created and run.
There is one producer thread, and 5 consumer threads.
void producer()
{