Threads, Processes
Version A
The Dining Philosophers Problem (simplified)
-
Demonstration
-
Description of the problem:
-
There is a number of resources, put in the circle (thus each of the resources
have two adjacent ones)
-
There is a number of threads, each scheduled to use two adjacent resources
simultaneously for the given period of time
-
Each thread tries to aquire both resources, one by one (the order is
not specified)
-
If any of the desired resources is being used by other thread, the thread waits
until it's free, but doesn't release the second resource (if it has been
succesfully aquired by this thread)
-
After both resources are aquired, the thread uses them for the given period of
time, and then releases them and ends up
-
The program:
-
the visualisation of the above problem
-
the list of the threads scheduled (if a particular thread has ended up, it
should be removed from the list)
-
the circle of resources
-
the resources used should be drawn in random colour, depending on the
thread (it should be different for each thread, but if the same colour is
given for two separate threads, don't care)
-
the resources, which are free, should be drawn white
-
Technical requirements:
-
No two threads can use the same resource at the same time
-
Use Critical Section, Semaphore or Mutex for synchronising the access to the
resources
-
The deadlock in such scenario is possible, however very unlikely, so
don't deal with it.
-
The visualisation should not flicker
-
No thread should be running after the main window is closed
-
The use of a Timer (CreateTimer, WM_TIMER) is forbidden
-
The use of busy waiting is forbidden
-
Hints:
-
CreateThread, _begin_thread()
-
CRITICAL_SECTION, CreateSemaphore(), CreateMutex()
-
WaitForSingleObject() (doesn't apply to CRITICAL_SECTION, so if you choose this
way of synchronisation, you need to deal with proper ending of the program in
some other way)
-
Approximate points:
-
the problem solution: 4.0
-
proper use and synchronisation of threads: 4.0
-
drawing: 2.0