Re: Thread initialization and condition



Am Fri, 04 Jan 2008 15:45:22 +0100 schrieb Joaquim Duran:

> Hello,
> 
> Andreas told in his previous email the he was already using a queue.
> The code to synchronize the thread should be similar to (pseucode):
> 
> Main thread:
> 
> Push a new file to queue (assuming STL like queue):
> mutex.lock()
> queue.push(fine_name);
> condition.signal();
> mutex.unlock();
> 
> 
> Stop a Job:
> mutex.lock();
> stop= true;
> condition.signal();
> mutex.unlock();
> 
> FTP Thread:
> 
> Get a file fro queue :
> 
> string fname;
> 
> mutex.lock();
> while ((!stop) && (queue.empty())
> {
> 	condition.wait();	
> }ards
> if (stop)
> {
> 	mutex.unlock();
> 	exit_thread();
> }
> 
> fname = queue.top();
> mutex.unlock();
> return fname;

I've done it now in a similar way as you sketched it above. The locking
and signaling works now on both machines. Thanks.

There's still one little problem while exiting and joining. But I hope
to solve it tomorrow.

regards
Andreas


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]