Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
chuck cranor
margo
Commits
132a30de
Commit
132a30de
authored
Apr 11, 2016
by
Shane Snyder
Browse files
add example illustrating sleep functionality
parent
fd88d80a
Changes
2
Show whitespace changes
Inline
Side-by-side
examples/Makefile.subdir
View file @
132a30de
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
\
...
...
examples/sleep.c
View file @
132a30de
...
@@ -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
((
arg
c
==
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
,
"
\t
sleep_seconds: number of seconds for each thread to sleep.
\n
"
);
fprintf
(
stderr
,
"
\t
ABT: use ABT sleep mechanism, rather than POSIX sleep.
\n
"
);
fprintf
(
stderr
,
"
\t
ABT: 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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment