1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <stdio.h>
17 #include <pthread.h>
18 #include "test.h"
19
20 pthread_cond_t cond;
21 pthread_mutex_t mutex;
22 int flag = 0;
23 pthread_t pid1;
24 pthread_t pid2;
25
threadfunc1(void * arg)26 void *threadfunc1(void *arg)
27 {
28 pthread_mutex_lock(&mutex);
29 pthread_cond_wait(&cond, &mutex);
30 flag++;
31 return 0;
32 }
33
threadfunc2(void * arg)34 void *threadfunc2(void *arg)
35 {
36 sleep(1);
37 pthread_mutex_lock(&mutex);
38 pthread_cond_signal(&cond);
39 if (flag != 1) {
40 t_error("pthread_cond_wait_0100 pthread_cond_wait error get flag is %d are not want 1\n", flag);
41 }
42 return 0;
43 }
44
45 /**
46 * @tc.name : pthread_cond_wait_0100
47 * @tc.desc : The parameter is valid, verify that the condition variable is activated
48 * @tc.level : Level 0
49 */
pthread_cond_wait_0100(void)50 void pthread_cond_wait_0100(void)
51 {
52 pthread_create(&pid1, NULL, threadfunc1, NULL);
53 pthread_create(&pid2, NULL, threadfunc2, NULL);
54 }
55
main(int argc,char * argv[])56 int main(int argc, char *argv[])
57 {
58 pthread_cond_wait_0100();
59 return t_status;
60 }