Skip to content

abel-mak/dining-philosophers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 

Repository files navigation

dining-philosophers

dining philosophers problem

philo

philosopher with threads and mutex
arguments: number_of_philosophers time_to_die time_to_eat time_to_sleep [number_of_times_each_philosopher_must_eat]

philo_bonus

philosopher with processes and semaphore
arguments: number_of_philosophers time_to_die time_to_eat time_to_sleep [number_of_times_each_philosopher_must_eat]

notes

  • pthread_mutex_lock(&N_mutex) ensures that exactly ONE thread is sucessful in locking the mutex variable N_mutex. This particular thread will then be the only thread that will update the variable N, thus ensuring that N is updated sequential (one thread after another)
  • So Thread Serialization means to make sure that a certain set of events occurs in a sequence not at the same time (src)
  • Reentrancy are Some functions designed to not use global variables, strtok (for tokenizing C character string, retains state between calls) is non reetrant function, Non-reentrant functions are dangerous for multithreaded programs (and also cause issues when called from recursive functions) (src)
  • Atomic Operation an operation during which a processor can simultaneously read a location and write it in the same bus operation. This prevents any other processor or I/O device from writing or reading memory until the operation is complete.

About

dining philosophers problem

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published