Use =default for skeleton copy constructor
[ACE_TAO.git] / ACE / examples / Threads / process_semaphore.cpp
blobe8c6718c7afa72d58ed31a7652828cc54ef14c52
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;
14 extern "C" void
15 handler (int)
17 done = 1;
20 int
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);
29 ACE_UNUSED_ARG (sa);
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"));
36 else
37 ACE_DEBUG ((LM_DEBUG, "(%P|%t) = acquired\n"));
39 ACE_OS::sleep (3);
41 if (pm.release () == -1)
42 ACE_DEBUG ((LM_DEBUG, "(%P|%t) = %p\n", "release failed"));
43 else
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"));
48 else
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"));
53 else
54 ACE_DEBUG ((LM_DEBUG, "(%P|%t) = released\n"));
57 if (argc > 2)
58 pm.remove ();
59 return 0;