A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
| inline |
side by side
Get rid of "%s" in second argument of function xbt_str_parse_*.
[simgrid.git]
/
examples
/
c
/
synchro-semaphore
/
synchro-semaphore.c
diff --git
a/examples/c/synchro-semaphore/synchro-semaphore.c
b/examples/c/synchro-semaphore/synchro-semaphore.c
index
f492e02
..
8e6de3b
100644
(file)
--- a/
examples/c/synchro-semaphore/synchro-semaphore.c
+++ b/
examples/c/synchro-semaphore/synchro-semaphore.c
@@
-20,14
+20,20
@@
static void peer(int argc, char* argv[])
{
int i = 0;
while (i < argc) {
- double wait_time = xbt_str_parse_double(argv[i], "Invalid wait time
: %s
");
+ double wait_time = xbt_str_parse_double(argv[i], "Invalid wait time");
i++;
sg_actor_sleep_for(wait_time);
- XBT_INFO("Trying to acquire %d", i);
- sg_sem_acquire(sem);
+ XBT_INFO("Trying to acquire %d (%sblocking)", i, sg_sem_would_block(sem) ? "" : "not ");
+ // cover the two cases: with and without timeout
+ if (i > 1) {
+ while (sg_sem_acquire_timeout(sem, 3.0))
+ XBT_INFO("Timeout.. Try again %d", i);
+ } else {
+ sg_sem_acquire(sem);
+ }
XBT_INFO("Acquired %d", i);
- wait_time = xbt_str_parse_double(argv[i], "Invalid wait time
: %s
");
+ wait_time = xbt_str_parse_double(argv[i], "Invalid wait time");
i++;
sg_actor_sleep_for(wait_time);
XBT_INFO("Releasing %d", i);
@@
-46,11
+52,12
@@
int main(int argc, char* argv[])
sg_host_t h = sg_host_by_name("Fafard");
sem = sg_sem_init(1);
+ XBT_INFO("Semaphore initialized with capacity = %d", sg_sem_get_capacity(sem));
const char* aliceTimes[] = {"0", "1", "3", "5", "1", "2", "5", "0"};
const char* bobTimes[] = {"0.9", "1", "1", "2", "2", "0", "0", "5"};
- sg_actor_create("Alice", h, peer, 8, aliceTimes);
- sg_actor_create("Bob", h, peer, 8, bobTimes);
+ sg_actor_create
_
("Alice", h, peer, 8, aliceTimes);
+ sg_actor_create
_
("Bob", h, peer, 8, bobTimes);
simgrid_run();
sg_sem_destroy(sem);