Created
April 14, 2016 18:33
-
-
Save albertzak/67bdffa95aa185e936365ecc6af928e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int run[] = { 0, 0 }; | |
int turn = 0; | |
/** | |
* Function to enter critical section. | |
*/ | |
void enterCriticalSection_dekker(int threadId) | |
{ | |
run[threadId] = 1; | |
while ( run[1 - threadId] != 0 ) { | |
if ( turn == (1 - threadId) ) { | |
run[threadId] = 0; | |
while ( turn == (1 - threadId) ) {} | |
run[threadId] = 1; | |
} | |
} | |
} | |
/** | |
* Function to leave critical section. | |
*/ | |
void leaveCriticalSection_dekker(int threadId) | |
{ | |
turn = (1 - threadId); | |
run[threadId] = 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment