root/test/threads/opal_thread.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. thr1_run
  2. thr2_run
  3. main

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
   2 /*
   3  * Copyright (c) 2010      Cisco Systems, Inc.  All rights reserved.
   4  * Copyright (c) 2014      The University of Tennessee and The University
   5  *                         of Tennessee Research Foundation.  All rights
   6  *                         reserved.
   7  * Copyright (c) 2018      Los Alamos National Security, LLC. All rights
   8  *                         reserved.
   9  * $COPYRIGHT$
  10  */
  11 
  12 #include "opal_config.h"
  13 
  14 #include <stdio.h>
  15 
  16 #include "support.h"
  17 #include "opal/constants.h"
  18 #include "opal/threads/threads.h"
  19 #include "opal/sys/atomic.h"
  20 
  21 
  22 /* Only have the body of this test if we have thread support */
  23 
  24 static opal_atomic_int_t count = 0;
  25 
  26 
  27 static void* thr1_run(opal_object_t* obj)
  28 {
  29     opal_atomic_add (&count, 1);
  30     return NULL;
  31 }
  32 
  33 static void* thr2_run(opal_object_t* obj)
  34 {
  35     opal_atomic_add (&count, 2);
  36     return NULL;
  37 }
  38 
  39 int main(int argc, char** argv)
  40 {
  41     int rc;
  42     opal_thread_t thr1;
  43     opal_thread_t thr2;
  44 
  45     test_init("opal_thread_t");
  46 
  47     OBJ_CONSTRUCT(&thr1, opal_thread_t);
  48     OBJ_CONSTRUCT(&thr2, opal_thread_t);
  49 
  50     thr1.t_run = thr1_run;
  51     thr2.t_run = thr2_run;
  52 
  53     rc = opal_thread_start(&thr1);
  54     test_verify_int(OPAL_SUCCESS, rc);
  55 
  56     rc = opal_thread_start(&thr2);
  57     test_verify_int(OPAL_SUCCESS, rc);
  58 
  59     rc = opal_thread_join(&thr1, NULL);
  60     test_verify_int(OPAL_SUCCESS, rc);
  61 
  62     rc = opal_thread_join(&thr2, NULL);
  63     test_verify_int(OPAL_SUCCESS, rc);
  64 
  65     test_verify_int(3, count);
  66     return test_finalize();
  67 }

/* [<][>][^][v][top][bottom][index][help] */