This FPGA design example runs on the NB3000, and shows the classic concurrency problem in real time programming. Five philosophers sit at dining table, where they must share their time between thinking and eating. There is a bowl of spaghetti in front of each philosopher, with one fork between each of the five plates of spaghetti (five forks in total).
Each philosopher needs to hold two forks to eat. Because there are limited forks available, deadlock can occur when each of them picks up one fork and then waits forever for another one. In this example the problem is solved using semaphores. Semaphores manage access to the five forks – ensuring that at least one fork is always available, so that as soon as any philosopher finishes eating and returns a fork, another can begin eating. This ensures that deadlock cannot occur. The plates are displayed on the TFT screen as well as the status of each philosophers. The example demonstrates the creation of pthreads,
pthread_join,
sem_wait to lock the semaphore,
sem_post to unlock the semaphore, draw bit map or string in graphics on TFT.
The TSK3000, VGA 32 bit TFT controller and SRAM controller are used in this example.
Altium Designer projects included in this download:
- NB3000_The_Dining_Philosophers_Problem.PrjFpg
- NB3000 The Dining Philosophers Problem.PrjEmb