philosophers_prep/subjects/7_limited_resources.txt

23 lines
983 B
Plaintext

Assignment name: limited_resources
Expected files: limited_resources.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
---------------------------------------------------------------------------------------
Simulate a library with 3 computers shared among 10 students:
- Each student (thread) wants to use a computer for 2-5 seconds (random time)
- Only 3 students can use computers simultaneously
- Implement a "semaphore" using mutexes and a counter variable
Print when students:
- Arrive at the library
- Get a computer
- Finish using the computer
- Leave the library
Usage: `./limited_resources`
Hint: Since POSIX semaphores are not allowed in the mandatory part,
implement your own semaphore with mutex + counter + condition logic.
This exercise simulates resource limitation like in Philosophers with forks.