1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| #include "usg_common.h"
| #include "sem_util.h"
| static int mem_pool_cond = SemUtil::get(0x2001, 0);
|
| void *run(void *varg) {
| sleep(5);
| // notify malloc
| SemUtil::set(mem_pool_cond, 1);
| }
|
| int main() {
|
| pthread_t tid;
| pthread_create(&tid, NULL, run, NULL);
| SemUtil::set(mem_pool_cond, 0);
| // wait for someone else to free space
| printf("waiting...\n");
| SemUtil::dec(mem_pool_cond);
| printf("weak...\n");
|
| }
|
|