2004-10-20 05:03:09 +04:00
|
|
|
#include "ompi_config.h"
|
2005-08-21 23:21:09 +04:00
|
|
|
|
2005-09-24 05:17:32 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2004-03-03 19:44:41 +03:00
|
|
|
#include "support.h"
|
2006-02-12 22:51:24 +03:00
|
|
|
#include "opal/constants.h"
|
2005-08-15 15:02:01 +04:00
|
|
|
#include "opal/threads/threads.h"
|
2006-02-12 22:51:24 +03:00
|
|
|
#include "opal/sys/atomic.h"
|
2004-03-03 19:44:41 +03:00
|
|
|
|
|
|
|
|
2005-03-27 15:52:09 +04:00
|
|
|
#if !OMPI_HAVE_THREAD_SUPPORT
|
|
|
|
|
2005-03-27 15:55:03 +04:00
|
|
|
/* If we don't have thread support, there's no point in running this
|
|
|
|
test */
|
|
|
|
|
2005-03-27 15:52:09 +04:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
printf("OMPI was compiled without thread support -- skipping this test\n");
|
|
|
|
return 77;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2005-03-27 15:55:03 +04:00
|
|
|
/* Only have the body of this test if we have thread support */
|
|
|
|
|
|
|
|
static volatile int count = 0;
|
|
|
|
|
|
|
|
|
2005-07-03 20:06:07 +04:00
|
|
|
static void* thr1_run(opal_object_t* obj)
|
2004-03-03 19:44:41 +03:00
|
|
|
{
|
2005-07-04 01:38:51 +04:00
|
|
|
opal_atomic_add(&count, 1);
|
2004-03-03 19:44:41 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-07-03 20:06:07 +04:00
|
|
|
static void* thr2_run(opal_object_t* obj)
|
2004-03-03 19:44:41 +03:00
|
|
|
{
|
2005-07-04 01:38:51 +04:00
|
|
|
opal_atomic_add(&count, 2);
|
2004-03-03 19:44:41 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
int rc;
|
2005-07-04 02:45:48 +04:00
|
|
|
opal_thread_t thr1;
|
|
|
|
opal_thread_t thr2;
|
2004-03-03 19:44:41 +03:00
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
test_init("opal_thread_t");
|
2004-03-03 19:44:41 +03:00
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
OBJ_CONSTRUCT(&thr1, opal_thread_t);
|
|
|
|
OBJ_CONSTRUCT(&thr2, opal_thread_t);
|
2004-03-03 19:44:41 +03:00
|
|
|
|
|
|
|
thr1.t_run = thr1_run;
|
|
|
|
thr2.t_run = thr2_run;
|
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
rc = opal_thread_start(&thr1);
|
2005-08-21 23:21:09 +04:00
|
|
|
test_verify_int(OPAL_SUCCESS, rc);
|
2004-03-03 19:44:41 +03:00
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
rc = opal_thread_start(&thr2);
|
2005-08-21 23:21:09 +04:00
|
|
|
test_verify_int(OPAL_SUCCESS, rc);
|
2004-03-03 19:44:41 +03:00
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
rc = opal_thread_join(&thr1, NULL);
|
2005-08-21 23:21:09 +04:00
|
|
|
test_verify_int(OPAL_SUCCESS, rc);
|
2004-03-03 19:44:41 +03:00
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
rc = opal_thread_join(&thr2, NULL);
|
2005-08-21 23:21:09 +04:00
|
|
|
test_verify_int(OPAL_SUCCESS, rc);
|
2004-03-03 19:44:41 +03:00
|
|
|
|
|
|
|
test_verify_int(3, count);
|
|
|
|
return test_finalize();
|
|
|
|
}
|
|
|
|
|
2005-03-27 15:52:09 +04:00
|
|
|
#endif /* OMPI_HAVE_THREAD_SUPPORT */
|