Model producer-consumer

The model producer-consumer is a data-processing example of Synchronization of resources. It can be considered in various contexts, we will tackle the problem in an environment Multi-thread.

That is to say a whole of producers, a consumer and a queue F. The problem is to synchronize the access to a printer.

The code carried out by the producers is the following:

to create a document D to lock F: to add D at the end of the file F to send a signal by F to the consuming process to unbolt F

And here the code carried out by the consumer:

to lock F: as long as there are consumers: to await signal of F for each element E of F: to print E end for to erase all the elements of the file F end such an amount of-that to unbolt F

The implementation is inspired by threads POSIX ( pthreads ). Please note that waiting of the signal is an operation which unbolts the associated Mutex, awaits a signal of another thread, then reverrouille the mutex once the received signal.

External bonds

  • Tutoriel on threads POSIX

Random links:Monarchism | Ostara | Salvien of Marseilles | Lopes handbook | Wings of Virginia | Maoual | Dans_le_pays_de_dernières_choses