1 // This program tests ACE_Process_Semaphore. To run it, open 3 or 4
2 // windows and run this program in each window...
4 #include "ace/OS_main.h"
5 #include "ace/OS_NS_unistd.h"
6 #include "ace/Signal.h"
7 #include "ace/Log_Msg.h"
8 #include "ace/Process_Semaphore.h"
9 #include "ace/OS_NS_stdlib.h"
12 static sig_atomic_t done
;
21 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
23 const ACE_TCHAR
*name
= argc
== 1 ? ACE_TEXT("hello") : argv
[1];
24 int iterations
= argc
> 2 ? ACE_OS::atoi (argv
[2]) : 100;
26 ACE_Process_Semaphore
pm (1, name
);
28 ACE_Sig_Action
sa ((ACE_SignalHandler
) handler
, SIGINT
);
31 for (int i
= 0; i
< iterations
&& !done
; i
++)
33 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) = acquiring\n"));
34 if (pm
.acquire () == -1)
35 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) = %p\n", "acquire failed"));
37 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) = acquired\n"));
41 if (pm
.release () == -1)
42 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) = %p\n", "release failed"));
44 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) = released\n"));
46 if (pm
.tryacquire () == -1)
47 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) = %p\n", "tryacquire failed"));
49 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) = tryacquire\n"));
51 if (pm
.release () == -1)
52 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) = %p\n", "release failed"));
54 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) = released\n"));