in reply to Re: need a thread to wait until a buffer is full.
in thread need a thread to wait until a buffer is full.

Ok, here is a better way to ask my question:

I have 2 threads, one creates shared variable that acts as a buffer, it puts a reference to the buffer in an array, then it waits until a second thread puts something into the buffer before continuing.

The second thread will pop/shift stuff out of the array every once in a while, fill the buffers according to some request that is sent with them.

I need to make sure the first thread waits until there is something in the buffer, I do not know when the buffer is going to be filled, and I have no idea how much data will be in the buffer when it is done, but it will be binary data, so it can be ANYTHING.

My idea was to create a loop in the first thread where it does the following (not necessarily in this order)
this is a loop, I figure the yield should come first since the first iteration will almost certainly be too soon. then it locks it, once it obtains the lock it checks it, if it is empty we reach the end of the loop. this is the part that worries me: at the end of the loop, the loop starts over, I am not sure if a loop iterating a second time will release the lock or not, I am sure it is, but it would be hard to debug if not.
so the code I get to do this is roughly this:
while (1) #Infinite loop { threads->yield(); #Yield each iteration lock($Buffer); #Lock buffer to prevent taking a partialy filled bu +ffer. last if ($Buffer); #If the buffer is filled continue. }

--------------------------------------

I would rather take 30 minutes to re-invent the wheel then take 30 days to learn how to use someone else's. Before pestering me about my re-invention prepare to defend yourself with a way of learning how to use the wheel in less time than it takes for me to make one, one that I might add is specialized to my specific task!