rlinsdev / 42-philosophers-aux

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Philosophers

42 Project Aux tests and definitions

Definitions

  • Data Races: Occur when multiple tasks or threads access a shared resource without sufficient protections
  • Mutex: MUTual EXclusion - Protect the execution again other threads running at the same time.
  • Semaphore: Some kind of mutex, but with counter

External functions.

function Description
memset ToDo
printf ToDo
malloc ToDo
free ToDo
write ToDo
usleep ToDo
gettimeofday sys/time.h - get / set time
pthread_create pthread.h - Thread creation
pthread_detach pthread.h - When a detached thread terminates, its resources are automatically released back to the system
pthread_join pthread.h - function waits for the thread specified by thread to terminate
pthread_mutex_init pthread.h - destroy and initialize a mutex
pthread_mutex_destroy pthread.h - destroy and initialize a mutex
pthread_mutex_lock pthread.h - lock and unlock a mutex
pthread_mutex_unlock pthread.h - lock and unlock a mutex

Commands:

#Generate code in machine language
$ gcc -S main.c
$ ./philo 5	86400000 3600000 28800000 2

To Test:

  • Valgrind with race condition

Links

Code Vault - Playlist

What are Race conditions?

Mutex in C?

Deadlock C?

Semaphores?

Dining philosophers problem

Dining philosophers problem 2

Dining philosophers problem 3

Dining philosophers problem 4

About


Languages

Language:C 81.3%Language:Makefile 14.9%Language:Assembly 3.8%