An open API service indexing awesome lists of open source software.

https://github.com/slavamuravey/philosophers

The demonstration how to synchronize the work of threads using mutex, semaphore and buffered channel on the example of the problem of dining philosophers.
https://github.com/slavamuravey/philosophers

Last synced: 2 months ago
JSON representation

The demonstration how to synchronize the work of threads using mutex, semaphore and buffered channel on the example of the problem of dining philosophers.

Awesome Lists containing this project

README

        

### Problem
We have N philosophers. Only M of N philosophers can have dinner at the same time.

### Solution

##### Only one philosopher can have dinner at the same time
We can use mutex to allow the work of only one thread at the same time.

##### More than one philosopher can have dinner at the same time
To allow more threads we can use semaphore or buffered channel (as alternative implementation of semaphore logic).

### Demo

To run the demonstration please do:

```shell script
go run ./cmd
```