Condition Variables for Pthreads
"Ubaidul Khan" <[email protected]> Thu, 24 Apr 2003 11:04:01 -0400
| Newsgroups | gmane.linux.ngpt.user |
|---|---|
| Message-ID | <[email protected]> |
Hi, I writing a program for a my operating systems class. The problem is similar to the producer/comsumer problem. The number of producer threds are provided through a command line parameter when the program is invoked. We are required to have a condition variable for each thread. This condition variable is checked by each thread before inserting an item into the queue. Once the thread inserts an item into the queue, it will signal the condition variable. A producer thread is not allowed to insert a second item into the queue, until the first job it submitted is taken care of by the consumer thread. When the consumer performs a job from the queue, it will signal the condition varialbe assocated with the thread that placed the job in the queue. This will allow the producer to wake up and push another job onto the queue. The problem I'm running into is that I have an array of condition variables with the size of the array known only to main, since it recieves the number of consumer threads to create at run time. I need to create these condition variable globally so both the producers and consumer can signal these condition variables. Any help is appreciated.