wangzhengquan
2020-07-14 e4ce347428a0d459c7561f7bb3e180f351c11a4f
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");
 
}