File: opal_thread.c

package info (click to toggle)
openmpi 2.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 99,912 kB
  • ctags: 55,589
  • sloc: ansic: 525,999; f90: 18,307; makefile: 12,062; sh: 6,583; java: 6,278; asm: 3,515; cpp: 2,227; perl: 2,136; python: 1,350; lex: 734; fortran: 52; tcl: 12
file content (79 lines) | stat: -rw-r--r-- 1,668 bytes parent folder | download | duplicates (2)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * Copyright (c) 2010      Cisco Systems, Inc.  All rights reserved.
 * Copyright (c) 2014      The University of Tennessee and The University
 *                         of Tennessee Research Foundation.  All rights
 *                         reserved.
 * $COPYRIGHT$
 */

#include "opal_config.h"

#include <stdio.h>

#include "support.h"
#include "opal/constants.h"
#include "opal/threads/threads.h"
#include "opal/sys/atomic.h"


#if !OPAL_ENABLE_MULTI_THREADS

/* If we don't have thread support, there's no point in running this
   test */

int main(int argc, char *argv[])
{
    printf("OMPI was compiled without thread support -- skipping this test\n");
    return 77;
}

#else

/* Only have the body of this test if we have thread support */

static volatile int count = 0;


static void* thr1_run(opal_object_t* obj)
{
    (void)opal_atomic_add(&count, 1);
    return NULL;
}

static void* thr2_run(opal_object_t* obj)
{
    (void)opal_atomic_add(&count, 2);
    return NULL;
}

int main(int argc, char** argv)
{
    int rc;
    opal_thread_t thr1;
    opal_thread_t thr2;

    test_init("opal_thread_t");

    OBJ_CONSTRUCT(&thr1, opal_thread_t);
    OBJ_CONSTRUCT(&thr2, opal_thread_t);

    thr1.t_run = thr1_run;
    thr2.t_run = thr2_run;

    rc = opal_thread_start(&thr1);
    test_verify_int(OPAL_SUCCESS, rc);

    rc = opal_thread_start(&thr2);
    test_verify_int(OPAL_SUCCESS, rc);

    rc = opal_thread_join(&thr1, NULL);
    test_verify_int(OPAL_SUCCESS, rc);

    rc = opal_thread_join(&thr2, NULL);
    test_verify_int(OPAL_SUCCESS, rc);

    test_verify_int(3, count);
    return test_finalize();
}

#endif /* OPAL_ENABLE_MULTI_THREADS */