philosophers_prep/subjects/2_mutex_basics.txt

18 lines
875 B
Plaintext

Assignment name: mutex_basics
Expected files: mutex_basics.c
Allowed functions: memset, printf, malloc, free, write, pthread_create, pthread_detach
pthread_join, pthread_mutex_init, pthread_mutex_destroy
pthread_mutex_lock, pthread_mutex_unlock, usleep, gettimeofday
--------------------------------------------------------------------------------------
Create a program with a global variable `counter` initialized to 0.
Launch 4 threads that increment this variable 1000 times each.
Use a mutex to protect access to the variable.
The program should print the final value of `counter` (should be 4000) and the total execution time.
Usage: `./mutex_basics`
Hint: Without a mutex, you will see incorrect values due to race conditions.
The mutex ensures that only one thread accesses the variable at a time.
This is the fundamental concept for the Philosophers project.