Pthreads meeting

Jerry Feldman gaf at blu.org
Thu May 19 09:01:01 EDT 2005


Last night I went through the client-server queuing example very quickly so 
I want to tie up a loose end, possibly. 
In general, what happens with a condition is:
lock mutex
test predicate
If the predicate is false:
	wait on the condition.
	Test the predicate after coming out of the wait. 
	If the predicate is false, then go back to the wait.
At this point the predicate is true and the mutex is acquired. 
Perform the required processing (in our case, remove data from queue).
unlock the mutex.
Perform any additional processing - in our case, write the data to the 
output file.
go back to step 1.

In the example, the predicate consists of two things, the RunFlag that tells 
the thread to terminate, and the number of elements on the queue. If the 
queue contains > 0 elements the thread removes the data from the queue and 
writes it to the file. 

If the RunFlag is set, it means that the server has detected an end of file, 
so terminate the thread. 

-- 
Jerry Feldman <gaf at blu.org>
Boston Linux and Unix user group
http://www.blu.org PGP key id:C5061EA9
PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9



More information about the Discuss mailing list