[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pthreads-users
Subject:    [pthreads-users] Condition Variables for Pthreads
From:       "Ubaidul Khan" <ukhanlists () hotmail ! com>
Date:       2003-04-24 15:04:01
[Download RAW message or body]

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.  


[Attachment #3 (text/html)]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1141" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Hi,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>I writing a program for a my operating systems 
class.&nbsp; The problem is similar to the producer/comsumer problem.&nbsp; The 
number of producer threds are provided through a command line parameter when the 
program is invoked.&nbsp; </FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>We are required to have a&nbsp;condition variable 
for each thread.&nbsp; This condition variable is checked by each thread before 
inserting an item into the queue.&nbsp; Once the thread inserts an item into the 
queue, it will signal the condition variable.&nbsp; 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&nbsp;consumer thread.&nbsp; &nbsp;</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>When the consumer performs a job from the queue, it 
will signal the condition varialbe assocated with the thread that placed the 
job&nbsp;in the queue.&nbsp; This will allow the producer to wake up and push 
another job onto the queue.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>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.&nbsp; I 
need to create these condition variable globally so both the producers and 
consumer can signal these condition variables.&nbsp; </FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Any help is appreciated.&nbsp; 
</FONT></DIV></BODY></HTML>

_______________________________________________
pthreads-users mailing list
pthreads-users@www-124.ibm.com
http://www-124.ibm.com/developerworks/oss/mailman/listinfo/pthreads-users

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic