Comments on Assignment #2: Turtle Race and Thread Synchronization, Assignments of Operating Systems

Important comments and suggestions regarding the implementation of the turtle race assignment in microsoft visual c++. Topics covered include the handling of ctrl-c, thread priority and blocking time, using waitformultipleobjects to find the winner, and changing the number of decimals in output reports. Recommended parameters and alternative methods are also suggested.

Typology: Assignments

Pre 2010

Uploaded on 03/28/2010

koofers-user-cup
koofers-user-cup 🇺🇸

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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).

Partial preview of the text

Download Comments on Assignment #2: Turtle Race and Thread Synchronization and more Assignments Operating Systems in PDF only on Docsity!

Important comments concerning the assignment

  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).