qingxing2005
Technical User
Dear all,
My program scenario is as follows.
Three threads (thread 1-3) will fetch values from the ring buffer. E.g. after one thread gets one value from ring buffer of which length is 100, the outputIndex of ring buffer will be decreased by one, per time.
Meanwhile, there is anther thread (thread 4), which has the functionality of re-filling the ringbuffer. E.g. when OutputIndex of ringbuffer equals to 0, the thread will start to re-fill the ringbuffer. Otherwise, it will be blocked/suspended.
My question is that how shall I play this scenario. I am newbie in thread, and there are not so many discriptive and simple thread programs. I wrote a snippet of code as follows. For my code, Although ringbuffer.outputIndex equals to 0, it is never initialized by thread 4. Is there anyone can help me a little?
DWORD WINAPI init_ringbuffer()
{
// ring buffer initialization.
...
}
void createThread_4(void)
{
HANDLE Handle_Of_Thread_4;
Handle_Of_Thread_4 = CreateThread( NULL,
0,
init_ringbuffer,
NULL,
CREATE_SUSPENDED,
NULL);
if (ringbuffer.outputIndex == 0)
{
ResumeThread( Handle_Of_Thread_4 );
}
else
{
//Keep thread blocked.
}
}
int main()
{
// Declaration of ring buffer.
createThread123();
createThread_4();
// Wait for all the threads terminate, and close them.
...
}
My program scenario is as follows.
Three threads (thread 1-3) will fetch values from the ring buffer. E.g. after one thread gets one value from ring buffer of which length is 100, the outputIndex of ring buffer will be decreased by one, per time.
Meanwhile, there is anther thread (thread 4), which has the functionality of re-filling the ringbuffer. E.g. when OutputIndex of ringbuffer equals to 0, the thread will start to re-fill the ringbuffer. Otherwise, it will be blocked/suspended.
My question is that how shall I play this scenario. I am newbie in thread, and there are not so many discriptive and simple thread programs. I wrote a snippet of code as follows. For my code, Although ringbuffer.outputIndex equals to 0, it is never initialized by thread 4. Is there anyone can help me a little?
DWORD WINAPI init_ringbuffer()
{
// ring buffer initialization.
...
}
void createThread_4(void)
{
HANDLE Handle_Of_Thread_4;
Handle_Of_Thread_4 = CreateThread( NULL,
0,
init_ringbuffer,
NULL,
CREATE_SUSPENDED,
NULL);
if (ringbuffer.outputIndex == 0)
{
ResumeThread( Handle_Of_Thread_4 );
}
else
{
//Keep thread blocked.
}
}
int main()
{
// Declaration of ring buffer.
createThread123();
createThread_4();
// Wait for all the threads terminate, and close them.
...
}