source: tests/concurrency/pthread/pthread_cond_test.cfa @ 190a833

Last change on this file since 190a833 was 10b5970, checked in by Michael Brooks <mlbrooks@…>, 2 weeks ago

Fix many test-suite- and libcfa-caused unused variable warnings.

In scope are easy fixes among tests whose sole warnings were unused variable. Reduces the wflags lax list by 40%.

  • Property mode set to 100644
File size: 1012 bytes
Line 
1/* small test of pthread cond */
2
3#include <fstream.hfa>
4#include <thread.hfa>
5#include <pthread.h>
6
7int done_flag = 0;
8pthread_mutex_t _mutex;
9pthread_cond_t cond;
10
11extern "C" {
12    void* S1( void * ) {
13        pthread_mutex_lock(&_mutex);
14        for (int i = 0; i < 1000; i++) sout | "S1 done " | i;
15        done_flag = 1;
16        pthread_mutex_unlock(&_mutex);
17        pthread_cond_signal(&cond);
18        return NULL;
19    }
20
21    void* S2( void * ) {
22        pthread_mutex_lock(&_mutex);
23        if (!done_flag) pthread_cond_wait(&cond, &_mutex);
24        sout | "S2 statement done!";
25        pthread_mutex_unlock(&_mutex);
26        return NULL;
27    }
28}
29
30
31
32int main() {
33    pthread_mutex_init(&_mutex, NULL);
34    pthread_cond_init(&cond, NULL);
35    pthread_t s1,s2;
36    pthread_create(&s1, NULL, S1, NULL);
37    pthread_create(&s2, NULL, S2, NULL);
38    void* res = NULL;
39    pthread_join(s1, &res);
40    pthread_join(s2, &res);
41    pthread_mutex_destroy(&_mutex);
42    pthread_cond_destroy(&cond);
43    return 0;
44}
Note: See TracBrowser for help on using the repository browser.