Entries tagged monitor concept

Dining Philosophers with monitor using pthread mutex and condition variables in C

Posted on 24. Mai 2012 Comments

I had to do this for uni a while ago so I thought I might as well publish it. The task was to implement the Dining philosophers problem in C. We had to use the monitor concept which is implemented with mutual exclusion (mutex) from the pthread-library because C lacks a built-in monitor function in contrary to e.g. Java, Python or Delphi. Bascially this just means, the critical things have to go between pthread_mutex_lock(&mutex) and pthread_mutex_unlock(&mutex) The communication from one philosopher to another was realized with condition variables(cond-vars). The realisation of thinking and eating should be done by to empty loops that go to a huge number(so it takes a while even on todays computers). A debug printout should be implemented as well to control everything is working as expected. Nearer details can be found in the doxygen documentation or directly in the sourcecode.

Download