-
-
Save rishabh-ink/5e14734f305ece78c7cf486b7f993c58 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
/* echotext.cpp */ | |
/* ... */ | |
/* create a mutex lock */ | |
static pthread_mutex_t echoLock; | |
void *echoThis(void *text) | |
{ | |
/* acquire the mutex lock */ | |
if(pthread_mutex_lock(&echoLock)) | |
{ | |
/* error acquiring lock */ | |
perror("pthread_mutex_lock"); | |
} | |
/* ... critical section code here ... */ | |
} | |
int main(int argc, char * argv[]) | |
{ | |
/* ... */ | |
/* initialize the mutex lock */ | |
if(pthread_mutex_init(&echoLock, NULL)) | |
{ | |
/* error initializing lock */ | |
perror("pthread_mutex_init"); | |
} | |
/* ... */ | |
/* remove the mutex */ | |
if(pthread_mutex_destroy(&echoLock)) | |
{ | |
/* error removing the mutex */ | |
perror("pthread_mutex_destroy"); | |
} | |
/* ... */ | |
} | |
/* end of echotext.cpp */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment