The curious case of recursive mutex

pthread_mutex_t mutex;
void func(){
pthread_mutex_lock(&mutex);
//Critical Section code
pthread_mutex_unlock(&mutex);
}
int main(){
pthread_mutex_init(&mutex,NULL);
return 0;
}
void func(){    pthread_mutex_lock(&mutex);
func();// Recursive call
pthread_mutex_unlock(&mutex);
}
pthread_mutex_t mutex;int main(){
pthread_mutexattr_t attr; //Attribute variable
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&mutex,&attr);
return 0;
}

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

BIS Certificate For Barcode Scanner | CRS Certification

7 Misconceptions Small Business Have about Intranet (SharePoint in particular)

The Hardest Parts of Working with a REST API

CS373 Spring 2022 Ricky Woodruff — Blog 10

SquadShaper: aVR experience for virtual team building and ice breaking

What is the actual job of JVM?

InsureDAO smart contracts are currently being audited by Quantstamp and Solidified.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vishal Vatsal

Vishal Vatsal

More from Medium

Serialization and Deserialization: How data travels in a computer network ?

Learning YAML and a Small Challenge

SimpleDB: A Basic RDBMS Built From Scratch

Buffering and Caching

Video buffering