gaoyuanyu
恒柔
2016-07-25 14:06

‘PTHREAD_MUTEX_RECURSIVE’ undeclared

报错‘PTHREAD_MUTEX_RECURSIVE’ undeclared (first use in this function):

程序如下:

1 #include
2 #include
3 #include
4 #include
5

6 int main(int argc,char *argv[]){
7 pthread_mutex_t mutex;
8

9 if(argc < 2){
10 printf("-usage:%s [error|normal|recursive]\n",argv[0]);
11 exit(1);
12 }
13 pthread_mutexattr_t mutexattr;
14 pthread_mutexattr_init(&mutexattr);
15 if(!strcmp(argv[1],"error")){
16 pthread_mutexattr_settype(&mutexattr,PTHREAD_MUTEX_RECURSIVE);
17 }/*else if(!strcmp(argv[1],"normal")){
18 pthread_mutexattr_settype(&mutexattr,PTHREAD_MUTEX_NORMAL);
19 }else if(!strcmp(argv[1],"recursive")){
20 pthread_mutexattr_settype(&mutexattr,PTHREAD_MUTEX_RECURSIVE);
21 }
22 pthread_mutex_init(&mutex,&mutexattr);
23 if(pthread_mutex_lock(&mutex) != 0){
24 printf("lock failure\n");
25 }else {
26 printf("lock success\n");

27 }
28 if(pthread_mutex_lock(&mutex) != 0){
29 printf("lock failure\n");
30 }else {
31 printf("lock success\n");

32 }
33
34 pthread_mutex_unlock(&mutex);
35 pthread_mutex_unlock(&mutex);
36 pthread_mutexattr_destroy(&mutexattr);
37 pthread_mutex_destroy(&mutex); */
38
39
40 return 0;
41 }

请问怎么回事啊?谢谢

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答