The way I understand it (someone correct me if this is wrong), when you've got a certain shared resource that, for one reason or another, can only be accessed by one process at a time, you'd use a semaphore.
Basically, the semaphore is a variable that keeps track of all the processes that currently want to access the shared resource and it makes sure only one process at a time actually accesses it.
Read these for more info:
http://www.ecst.csuchico.edu/~beej/g...emaphores.html
http://www.cs.cf.ac.uk/Dave/C/node26.html
http://metalink.oracle.com/cgi-bin/c...e_cr.cgi?20766
http://www.cim.mcgill.ca/~franco/OpS...es/node30.html
http://www.acm.uiuc.edu/lug/presenta...m-5.html#ss5.5