2024-07-01 09:57:08 -05:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2017 Intel Corporation. All rights reserved.
|
|
|
|
|
* This software is available to you under the BSD license below:
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or
|
|
|
|
|
* without modification, are permitted provided that the following
|
|
|
|
|
* conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* - Redistributions of source code must retain the above
|
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
|
* disclaimer.
|
|
|
|
|
*
|
|
|
|
|
* - Redistributions in binary form must reproduce the above
|
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
|
* disclaimer in the documentation and/or other materials
|
|
|
|
|
* provided with the distribution.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* Thread wait test: Test whether a store performed by one thead will wake up a
|
2024-11-25 14:12:15 -06:00
|
|
|
* second thread from a call to rocshmem_wait. */
|
2024-07-01 09:57:08 -05:00
|
|
|
|
|
|
|
|
#include <pthread.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
2024-11-25 14:12:15 -06:00
|
|
|
#include <rocshmem/rocshmem.hpp>
|
2024-07-01 09:57:08 -05:00
|
|
|
|
|
|
|
|
using namespace rocshmem;
|
|
|
|
|
|
|
|
|
|
static long *shr_var;
|
|
|
|
|
|
|
|
|
|
static void *src_thread_fn(void *arg) {
|
|
|
|
|
/* Try to get the dst thread to enter wait before the call to sleep */
|
|
|
|
|
sleep(1);
|
|
|
|
|
|
|
|
|
|
/* This should wake up the waiting dst thread */
|
|
|
|
|
*shr_var = 1;
|
|
|
|
|
|
|
|
|
|
/* Quiet should provide a store fence */
|
2024-11-25 14:12:15 -06:00
|
|
|
rocshmem_quiet();
|
2024-07-01 09:57:08 -05:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void *dst_thread_fn(void *arg) {
|
2024-11-25 14:12:15 -06:00
|
|
|
rocshmem_long_wait_until(shr_var, ROCSHMEM_CMP_NE, 0);
|
2024-07-01 09:57:08 -05:00
|
|
|
printf("shr_var is now %ld\n", *shr_var);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
|
int tl, ret;
|
|
|
|
|
pthread_t src_thread, dst_thread;
|
|
|
|
|
|
2024-11-25 14:12:15 -06:00
|
|
|
rocshmem_init_thread(ROCSHMEM_THREAD_MULTIPLE, &tl);
|
2024-07-01 09:57:08 -05:00
|
|
|
|
2024-11-25 14:12:15 -06:00
|
|
|
if (tl != ROCSHMEM_THREAD_MULTIPLE) {
|
2024-07-01 09:57:08 -05:00
|
|
|
printf("Init failed (requested thread level %d, got %d)\n",
|
2024-11-25 14:12:15 -06:00
|
|
|
ROCSHMEM_THREAD_MULTIPLE, tl);
|
|
|
|
|
rocshmem_global_exit(1);
|
2024-07-01 09:57:08 -05:00
|
|
|
}
|
|
|
|
|
|
2024-11-25 14:12:15 -06:00
|
|
|
shr_var = (long *)rocshmem_malloc(sizeof(long));
|
2024-07-01 09:57:08 -05:00
|
|
|
*shr_var = 0;
|
|
|
|
|
|
|
|
|
|
pthread_create(&dst_thread, NULL, &dst_thread_fn, NULL);
|
|
|
|
|
pthread_create(&src_thread, NULL, &src_thread_fn, NULL);
|
|
|
|
|
|
|
|
|
|
pthread_join(dst_thread, NULL);
|
|
|
|
|
pthread_join(src_thread, NULL);
|
|
|
|
|
|
2024-11-25 14:12:15 -06:00
|
|
|
rocshmem_free(shr_var);
|
2024-07-01 09:57:08 -05:00
|
|
|
|
2024-11-25 14:12:15 -06:00
|
|
|
rocshmem_finalize();
|
2024-07-01 09:57:08 -05:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|