summaryrefslogtreecommitdiff
path: root/ACE/examples/Semaphores
diff options
context:
space:
mode:
authorJohnny Willemsen <jwillemsen@remedy.nl>2008-02-13 12:41:57 +0000
committerJohnny Willemsen <jwillemsen@remedy.nl>2008-02-13 12:41:57 +0000
commit74612787eb1b3b72f4255ed969c496fb73de598f (patch)
treec2ce65ff5a37607b00d405d40a25b3c90d6024b6 /ACE/examples/Semaphores
parentaa87fd858d992c77c04fe9322890ce213b76ffc6 (diff)
downloadATCD-74612787eb1b3b72f4255ed969c496fb73de598f.tar.gz
Wed Feb 13 12:41:12 UTC 2008 Johnny Willemsen <jwillemsen@remedy.nl>
Diffstat (limited to 'ACE/examples/Semaphores')
-rw-r--r--ACE/examples/Semaphores/README17
-rw-r--r--ACE/examples/Semaphores/Semaphores.mpc17
-rw-r--r--ACE/examples/Semaphores/starter.cpp20
-rw-r--r--ACE/examples/Semaphores/worker.cpp29
4 files changed, 83 insertions, 0 deletions
diff --git a/ACE/examples/Semaphores/README b/ACE/examples/Semaphores/README
new file mode 100644
index 00000000000..a2133c13e35
--- /dev/null
+++ b/ACE/examples/Semaphores/README
@@ -0,0 +1,17 @@
+// $Id$
+
+This is a small example how to use process semaphores. We use it to
+synchronize between multiple processes and it was used to analyze
+some differences between ACE 5.6 and 5.6.2.
+
+To run do:
+1. Start a init-app. It will create the semaphore a go to sleep.
+2. Start a worker-app while the init-app still sleeps. This worker app will
+block on the semaphore.
+3. The init-app wakes up and releases the semahpre and exists.
+4. The worker-app will now lock the semphore and go to sleep.
+5. Start another worker-app while the first worker-app still sleeps. It will
+block on the semaphore.
+6. The first worker-app finally wakes up and releases the semaphore and
+start doing its work.
+
diff --git a/ACE/examples/Semaphores/Semaphores.mpc b/ACE/examples/Semaphores/Semaphores.mpc
new file mode 100644
index 00000000000..2da84df7239
--- /dev/null
+++ b/ACE/examples/Semaphores/Semaphores.mpc
@@ -0,0 +1,17 @@
+// -*- MPC -*-
+// $Id$
+
+project(*starter) : aceexe {
+ exename = starter
+
+ Source_Files {
+ starter.cpp
+ }
+}
+project(*worker) : aceexe {
+ exename = worker
+
+ Source_Files {
+ worker.cpp
+ }
+}
diff --git a/ACE/examples/Semaphores/starter.cpp b/ACE/examples/Semaphores/starter.cpp
new file mode 100644
index 00000000000..949e2dcec3b
--- /dev/null
+++ b/ACE/examples/Semaphores/starter.cpp
@@ -0,0 +1,20 @@
+// $Id$
+
+#include "ace/Process_Semaphore.h"
+#include "ace/OS_NS_unistd.h"
+#include "ace/Log_Msg.h"
+
+int main(int, char**)
+{
+ // Create locked
+ ACE_Process_Semaphore s (0, ACE_TEXT("AceTest"));
+
+ ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Starter has created and acquired semaphore\n")));
+
+ // Do some init stuff. Simulated by a sleep...
+ ACE_OS::sleep(10);
+
+ s.release();
+
+ ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Starter has released semaphore\n")));
+}
diff --git a/ACE/examples/Semaphores/worker.cpp b/ACE/examples/Semaphores/worker.cpp
new file mode 100644
index 00000000000..fd87e05715d
--- /dev/null
+++ b/ACE/examples/Semaphores/worker.cpp
@@ -0,0 +1,29 @@
+// Id$
+
+#include "ace/Process_Semaphore.h"
+#include "ace/OS_NS_unistd.h"
+#include "ace/Log_Msg.h"
+
+int main(int, char**)
+{
+ // Create locked
+ ACE_Process_Semaphore s (0, ACE_TEXT ("AceTest"));
+
+ ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Worker is going to acquire semaphore\n")));
+
+ s.acquire ();
+
+ ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Worker has acquired semaphore\n")));
+
+ // Do some init stuff. Simulated by a sleep...
+ ACE_OS::sleep(10);
+
+ s.release();
+
+ ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Worker released semaphore\n")));
+
+ // Do the work...
+ ACE_OS::sleep(5);
+
+ return 0;
+}