9 FailedOn(const char *f
, int e
) : func(f
), eno(e
) {}
18 if (sem_init(&mySemaphore
, 0, 0) != 0)
19 throw FailedOn("sem_init", errno
);
21 std::cerr
<< "Calling sem_trywait\n";
22 if (sem_trywait(&mySemaphore
) != 0) {
24 throw FailedOn("sem_trywait", errno
);
26 std::cerr
<< "Wait would have blocked" << std::endl
;
28 std::cerr
<< "Wait succeeded" << std::endl
;
31 if (sem_destroy(&mySemaphore
) != 0)
32 throw FailedOn("sem_destroy", errno
);
35 } catch (FailedOn
&e
) {
36 std::cerr
<< e
.func
<< " failed: " << strerror(e
.eno
) << std::endl
;
38 std::cerr
<< "Unknown exception" << std::endl
;