Commit 132a30de authored by Shane Snyder's avatar Shane Snyder

add example illustrating sleep functionality

parent fd88d80a
bin_PROGRAMS += examples/client examples/server examples/server-hang examples/client-timeout
bin_PROGRAMS += examples/client examples/server examples/server-hang examples/client-timeout examples/sleep
examples_server_SOURCES = \
examples/server.c \
......
......@@ -7,11 +7,14 @@
#include <stdio.h>
#include <assert.h>
#include <unistd.h>
#include <stdlib.h>
#include <ctype.h>
#include <abt.h>
#include <abt-snoozer.h>
#include <margo.h>
static int use_abt_sleep;
static int use_abt_sleep = 0;
static int sleep_seconds = 2;
static void sleep_fn(void *arg);
......@@ -27,19 +30,26 @@ int main(int argc, char **argv)
hg_context_t *hg_context;
hg_class_t *hg_class;
if(argc == 1)
int arg_ndx = 1;
if(argc > 1)
{
use_abt_sleep = 0;
}
else if((argc == 2) && (strcmp(argv[1], "ABT") == 0))
{
use_abt_sleep = 1;
}
else
{
fprintf(stderr, "Usage: %s [ABT]\n", argv[0]);
fprintf(stderr, "\tABT: use ABT sleep mechanism, rather than POSIX sleep.\n");
return(-1);
if(isdigit(argv[1][0]))
{
sleep_seconds = atoi(argv[1]);
arg_ndx++;
}
if((arg_ndx < argc) && (strcmp(argv[arg_ndx], "ABT") == 0))
{
use_abt_sleep = 1;
arg_ndx++;
}
if(arg_ndx != argc)
{
fprintf(stderr, "Usage: %s [sleep_seconds] [ABT]\n", argv[0]);
fprintf(stderr, "\tsleep_seconds: number of seconds for each thread to sleep.\n");
fprintf(stderr, "\tABT: use ABT sleep mechanism, rather than POSIX sleep.\n");
return(-1);
}
}
/* boilerplate HG initialization steps */
......@@ -90,11 +100,8 @@ int main(int argc, char **argv)
}
/* actually start margo */
/* provide argobots pools for driving communication progress and
* executing rpc handlers as well as class and context for Mercury
* communication. The rpc handler pool is null in this example program
* because this is a pure client that will not be servicing rpc requests.
*/
/* use a single pool for progress and sleeper threads */
/* NOTE: no rpc handler threads are needed */
/***************************************/
mid = margo_init(pool, ABT_POOL_NULL, hg_context, hg_class);
for(i=0; i<4; i++)
......@@ -147,9 +154,9 @@ static void sleep_fn(void *arg)
int my_tid = *(int *)arg;
if(use_abt_sleep)
margo_thread_sleep(2*1000.0);
margo_thread_sleep(sleep_seconds*1000.0);
else
sleep(2);
sleep(sleep_seconds);
printf("TID: %d sleep end\n", my_tid);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment