File: tlocal-test.c

package info (click to toggle)
python-cffi 1.9.1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,440 kB
  • ctags: 4,423
  • sloc: python: 25,052; ansic: 12,528; asm: 116; makefile: 97; sh: 28
file content (47 lines) | stat: -rw-r--r-- 833 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
#include <assert.h>
#include "thread-test.h"

#define NTHREADS 10


extern int add1(int, int);

static sem_t done;


static void *start_routine(void *arg)
{
    int i, x, expected, status;

    expected = add1(40, 2);
    assert((expected % 1000) == 42);

    for (i=0; i<10; i++) {
        x = add1(50, i);
        assert(x == expected + 8 + i);
    }

    status = sem_post(&done);
    assert(status == 0);

    return arg;
}

int main(void)
{
    pthread_t th;
    int i, status = sem_init(&done, 0, 0);
    assert(status == 0);

    for (i = 0; i < NTHREADS; i++) {
        status = pthread_create(&th, NULL, start_routine, NULL);
        assert(status == 0);
    }
    for (i = 0; i < NTHREADS; i++) {
        status = sem_wait(&done);
        assert(status == 0);
    }
    printf("done\n");
    return 0;
}