(Latest Revision: Sun Oct 29 00:47:07 PDT 2017 )
=================================== These are runs of my solution program. There is synchronization. The messages are printed in an order consistent with the tasks being performed according to a correct sequence. The program does not have the same output each time it is run, because many things happen 'by chance' depending on which thread the scheduler chooses to run, and when. (Also, this version of the program has its own programmed random delays.) However, the execution of the protocol assures that the outputs are always correct - assuming there are no bugs - none are known at this time. =================================== john@lucifer: head -29 sequence.cpp /* ---------------0--------------- -------3--------------5-------- ------------------------------- ------------------------------- -----------1-------2----------- ------------------------------- ------------------------------- ---------------4--------------- Constraints: * Threads 0, 1, and 2 should proceed to complete their work as soon as possible after they are created. * Thread 3 must wait for threads 0 and 1 to finish before thread 3 begins its work. However, thread 3 should begin and complete its work as soon as possible after threads 0 and 1 are finished. * The constraints for threads 4 and 5 are like those for thread 3, except that thread 4 waits for threads 1 and 2 to finish before starting, and thread 5 waits for threads 0 and 2. Also, each child thread increments the counter called thrds_finished just before exiting. (Note that access to this counter is a critical section problem.) The mother thread reports the value of thrds_finished just before the program stops. */ /* Thread Sequencing Program */ john@lucifer: sequence Welcome to The Child Thread Workplace! Mother Begins Spawning Threads. Mother Finishes Spawning Threads. Child # 2 has completed its assignment. Child # 0 has completed its assignment. Child # 1 has completed its assignment. Child # 5 has completed its assignment. Child # 3 has completed its assignment. Child # 4 has completed its assignment. All children have now reported that they finished. The value of the thrds_finished counter is: 6. Mother exiting ... john@lucifer: sequence Welcome to The Child Thread Workplace! Mother Begins Spawning Threads. Mother Finishes Spawning Threads. Child # 0 has completed its assignment. Child # 1 has completed its assignment. Child # 2 has completed its assignment. Child # 3 has completed its assignment. Child # 5 has completed its assignment. Child # 4 has completed its assignment. All children have now reported that they finished. The value of the thrds_finished counter is: 6. Mother exiting ... john@lucifer: sequence Welcome to The Child Thread Workplace! Mother Begins Spawning Threads. Child # 0 has completed its assignment. Mother Finishes Spawning Threads. Child # 1 has completed its assignment. Child # 2 has completed its assignment. Child # 3 has completed its assignment. Child # 5 has completed its assignment. Child # 4 has completed its assignment. All children have now reported that they finished. The value of the thrds_finished counter is: 6. Mother exiting ... john@lucifer: sequence Welcome to The Child Thread Workplace! Mother Begins Spawning Threads. Child # 2 has completed its assignment. Mother Finishes Spawning Threads. Child # 0 has completed its assignment. Child # 1 has completed its assignment. Child # 3 has completed its assignment. Child # 5 has completed its assignment. Child # 4 has completed its assignment. All children have now reported that they finished. The value of the thrds_finished counter is: 6. Mother exiting ... john@lucifer: