Skip to content

Instantly share code, notes, and snippets.

@rishabh-ink
Created February 3, 2018 21:59
Show Gist options
  • Save rishabh-ink/5e14734f305ece78c7cf486b7f993c58 to your computer and use it in GitHub Desktop.
Save rishabh-ink/5e14734f305ece78c7cf486b7f993c58 to your computer and use it in GitHub Desktop.
/* 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