|
-
March 10th, 2009, 08:43 AM
#1
Implementing queue as a class and threads
Hi all,
my requirement is there is a function which creates one thread and passes the data for further processing which looks like
void MyFunc(char *data)
{
CreateThread(NULL,0,build_data,(void *)data,0,NULL);
}
Now i want to modify the above code.
I want to introduce a queue class and want to create two threads so that 1st thread can invoke a function which writes the data to the queue and the 2nd thread reads the data from the queue. Please introduce mutex if required.
Can you tell me how to implement the above in VC++.
-
March 10th, 2009, 12:27 PM
#2
Re: Implementing queue as a class and threads
It's very simple, you just lock a critical section in every function that accesses the queue.
Code:
CCriticalSection cs;
void read_queue() {
cs.Lock();
queue.read( ...
cs.Unlock();
}
Nobody cares how it works as long as it works
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|