Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132929 views
License: OTHER
1
/* Example code for Software Systems at Olin College.
2
3
Copyright 2012 Allen Downey
4
License: Creative Commons Attribution-ShareAlike 3.0
5
6
*/
7
8
#include <stdlib.h>
9
#include <pthread.h>
10
#include "mutex.h"
11
12
Mutex *make_mutex()
13
{
14
Mutex *mutex = (Mutex *) malloc(sizeof(Mutex));
15
pthread_mutex_init(mutex->mutex, NULL);
16
return mutex;
17
}
18
19
void mutex_lock(Mutex *mutex)
20
{
21
pthread_mutex_lock(mutex->mutex);
22
}
23
24
void mutex_unlock(Mutex *mutex)
25
{
26
pthread_mutex_unlock(mutex->mutex);
27
}
28
29