blob: 661d3224d73f8c1bd59c52ed054dfffa1e65f0f3 (
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
33
34
35
36
37
38
39
40
41
42
43
44
45
|
/*
* Test for pthread_once().
*
* Depends on functions: pthread_create.
*/
#include <pthread.h>
#include <stdio.h>
pthread_once_t once = PTHREAD_ONCE_INIT;
void
myfunc(void)
{
printf("only see this once\n");
}
void *
mythread(void * arg)
{
int rc = pthread_once(&once, myfunc);
printf("returned %d\n", rc);
return 0;
}
int
main()
{
int rc;
pthread_t t1, t2;
if (pthread_create(&t1, NULL, mythread, NULL) != 0)
{
return 1;
}
if (pthread_create(&t2, NULL, mythread, NULL) != 0)
{
return 1;
}
Sleep(2000);
return 0;
}
|