blob: 144ce608d1f68c44efe9bab7fd2fc330cb735f1e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
/* All OK */
#include <pthread.h>
static pthread_mutex_t mx = PTHREAD_MUTEX_INITIALIZER;
static int shared;
static void *th(void *v)
{
pthread_mutex_lock(&mx);
shared++;
pthread_mutex_unlock(&mx);
return 0;
}
int main()
{
pthread_t a, b;
pthread_mutex_lock(&mx);
pthread_mutex_unlock(&mx);
pthread_create(&a, NULL, th, NULL);
pthread_create(&b, NULL, th, NULL);
pthread_join(a, NULL);
pthread_join(b, NULL);
return 0;
}
|