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

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_SOURCES = \
examples/server.c \ examples/server.c \
......
...@@ -7,11 +7,14 @@ ...@@ -7,11 +7,14 @@
#include <stdio.h> #include <stdio.h>
#include <assert.h> #include <assert.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h>
#include <ctype.h>
#include <abt.h> #include <abt.h>
#include <abt-snoozer.h> #include <abt-snoozer.h>
#include <margo.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); static void sleep_fn(void *arg);
...@@ -27,20 +30,27 @@ int main(int argc, char **argv) ...@@ -27,20 +30,27 @@ int main(int argc, char **argv)
hg_context_t *hg_context; hg_context_t *hg_context;
hg_class_t *hg_class; hg_class_t *hg_class;
if(argc == 1) int arg_ndx = 1;
if(argc > 1)
{ {
use_abt_sleep = 0; if(isdigit(argv[1][0]))
{
sleep_seconds = atoi(argv[1]);
arg_ndx++;
} }
else if((argc == 2) && (strcmp(argv[1], "ABT") == 0)) if((arg_ndx < argc) && (strcmp(argv[arg_ndx], "ABT") == 0))
{ {
use_abt_sleep = 1; use_abt_sleep = 1;
arg_ndx++;
} }
else if(arg_ndx != argc)
{ {
fprintf(stderr, "Usage: %s [ABT]\n", argv[0]); 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"); fprintf(stderr, "\tABT: use ABT sleep mechanism, rather than POSIX sleep.\n");
return(-1); return(-1);
} }
}
/* boilerplate HG initialization steps */ /* boilerplate HG initialization steps */
/***************************************/ /***************************************/
...@@ -90,11 +100,8 @@ int main(int argc, char **argv) ...@@ -90,11 +100,8 @@ int main(int argc, char **argv)
} }
/* actually start margo */ /* actually start margo */
/* provide argobots pools for driving communication progress and /* use a single pool for progress and sleeper threads */
* executing rpc handlers as well as class and context for Mercury /* NOTE: no rpc handler threads are needed */
* communication. The rpc handler pool is null in this example program
* because this is a pure client that will not be servicing rpc requests.
*/
/***************************************/ /***************************************/
mid = margo_init(pool, ABT_POOL_NULL, hg_context, hg_class); mid = margo_init(pool, ABT_POOL_NULL, hg_context, hg_class);
for(i=0; i<4; i++) for(i=0; i<4; i++)
...@@ -147,9 +154,9 @@ static void sleep_fn(void *arg) ...@@ -147,9 +154,9 @@ static void sleep_fn(void *arg)
int my_tid = *(int *)arg; int my_tid = *(int *)arg;
if(use_abt_sleep) if(use_abt_sleep)
margo_thread_sleep(2*1000.0); margo_thread_sleep(sleep_seconds*1000.0);
else else
sleep(2); sleep(sleep_seconds);
printf("TID: %d sleep end\n", my_tid); 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