The Art of Concurrency by Breshears Clay

The Art of Concurrency by Breshears Clay

Author:Breshears, Clay [Clay Breshears]
Language: eng
Format: epub
Tags: COMPUTERS / Software Development & Engineering / General
ISBN: 9780596555788
Publisher: O'Reilly Media
Published: 2009-05-06T16:00:00+00:00


This example uses a while loop to keep threads executing passes as long as there is still a chance that some data remains to be sorted. For each pass through the data, the maximum number of unsorted elements (iCounter) is accessed (protected by the CRITICAL_SECTION object BLock[0]) and stored locally in i. If the number of potential unsorted items is less than or equal to zero, the sorting is done and the Done flag is set. When other threads complete their current pass, the while conditional test will terminate them. Before this determination is made, the index of the last slot in the first data zone is stored in releasePoint.

The j loop passes through the array element by element, compares the values of A[j] with A[j+1], and swaps them if they are out of order. If the thread has reached the end of the current data zone, it releases the CRITICAL_SECTION object on that zone and waits for the thread in the next zone to release that lock before proceeding. Once the end of the array has been reached, the thread in that zone releases the last CRITICAL_SECTION object used. If no exchanges were made during the just completed pass, the thread sets the Done flag.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.