
Important comments concerning the assignment #2
1. CTRL-C handler: if it returns FALSE the primary thread terminates; if it returns TRUE the primary
thread, or any running secondary thread continues to run.
2. If you invoke p23 (in part C) as: p23 2 0.25 1000, as you would do in parts A and B, then the other
threads (even those with lower priority) have chance to run because the high priority thread is blocked.
Consequently there would be no help to the favorite turtle. Therefore there must be very small (or none)
blocking time. Now, if the blocking time is too small, then the race would finish too fast, and you
wouldn’t have time to hit the CTRL-C key. Good parameters are: p23 2000 0.001 0. You use this
however only for your own purpose.
3. Command p23 2000 0.001 0 is removed from the file turnin2.bat because it is difficult to
know when to press CTRL-C on medusa (beep can't be heard) when invoking programs from a batch file..
4. The problem of finding the winner can be solved by using the return value of the
WaitForMultipleObjects. The value is the index of the handle array that corresponds to the
signaled thread (n-WAIT_OBJECT_0). If there are several signaled threads in time of the call, then it is
the lowest index (that may be a problem).
5. Instead of using Sleep(dt) in main, you can use timeout:
WaitForMultipleObjects(N,h,FALSE,dt).
6. If you use stream I/O (cout), you can change the number of decimals in your output report by using the
statement: cout.precision(4) (this for example lowers the number of decimals to four).