本次加拿大代写是一个计算机线程的assignment

Purpose: To explore threads and synchronization techniques.

Description: You are to create 3 programs. Programs 1 and 2 are nearly identical. Each contain a single button that when pressed signals Program3 to begin. Obviously you must have executed all 3 programs. Note that the order of execution does not matter. When the main program starts, it indicates in the Title Bar which program called it to start first. main program shows 5 “cars” (buttons) labeled by a colour name. When the user clicks the LEFT mouse button while the cursor is on the window (anywhere but the buttons themselves) the “cars” race to the finish line that is exactly in the middle of the window (and adjusts if resized, even during the “race”). The first car to reach the finish line “wins” and a message box with the winners “name” is displayed. Each “car” is controlled by a thread. If the user performs a right mouse click instead of a left mouse click to START the race the race will be synchronized.

  • Each “car”s thread uses the SAME threadproc
  • Do NOT put synchronization code inside the threadproc – your threadproc should call a function that determines the winner based on where that car is and the finish line value.
  • Your code MUST normally result in a “race condition” ie. more than one car usually “wins”. Synchronization should remove the race condition. Use a boolean flag to turn on or off the synchronization. Put the synchronization code in the same function that causes the race condition (i.e. don’t create two versions of the same function). You will need to use Sleep() to force a race condition. I also use a really large empty for loop to add more “work” that each thread performs during each iteration to move the “car”
  • You need to use synchronization to control the processes (starting main program via Part2 or 3, ending Part2 or 3 via closing main program).
  • When Part1 closes it signals Part2 and Part3 to exit. In the example provided it requires the button on Part2 and Part3 to be pressed for it to hear the closing signal. However full FULL marks, yours should close the two programs even if the program Part2 or Part3 never had it’s button pressed

Marking

Function Mark

Part2 or Part3 starts main program 3
main program indicates which program started it 3
main program signals Part2 and Part3 to end 3
When mouse clicked buttons race to finish line using threads 3
Buttons on Part2/Part3 do not have to be pressed to respond to
Part1closing button 3
Unsynced causes “race condition” to usually occur 3
Synced removes “race condition” using appropriate techniques 3 *requires unsync