summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschmidt <douglascraigschmidt@users.noreply.github.com>1998-09-30 17:26:14 +0000
committerschmidt <douglascraigschmidt@users.noreply.github.com>1998-09-30 17:26:14 +0000
commitbf228a58f2ec8c9dbaa4cb1405460a801b2e6c12 (patch)
tree2848b7ff33b44ce882b86d48b18b2c96ea0ea3d2
parent46f20d8ee0b92bc53de0e636e95bf7d9999c5673 (diff)
downloadATCD-bf228a58f2ec8c9dbaa4cb1405460a801b2e6c12.tar.gz
.
-rw-r--r--examples/System_V_IPC/SV_Semaphores/Semaphores_2.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/examples/System_V_IPC/SV_Semaphores/Semaphores_2.cpp b/examples/System_V_IPC/SV_Semaphores/Semaphores_2.cpp
index f9fb597889d..9afa1ff8dbf 100644
--- a/examples/System_V_IPC/SV_Semaphores/Semaphores_2.cpp
+++ b/examples/System_V_IPC/SV_Semaphores/Semaphores_2.cpp
@@ -26,9 +26,13 @@ parent (char *shm)
{
char *s = shm;
+ // Both semaphores are initially created with a count of 0, i.e.,
+ // they are "locked."
ACE_SV_Semaphore_Complex mutex (SEM_KEY_1, ACE_SV_Semaphore_Complex::ACE_CREATE, 0);
ACE_SV_Semaphore_Complex synch (SEM_KEY_2, ACE_SV_Semaphore_Complex::ACE_CREATE, 0);
+ // This is a critical section, which is protected by the mutex
+ // semaphore.
for (char c = 'a'; c <= 'z'; c++)
*s++ = c;
@@ -51,9 +55,15 @@ parent (char *shm)
static int
child (char *shm)
{
+ // Both semaphores are initially created with a count of 0, i.e.,
+ // they are "locked."
ACE_SV_Semaphore_Complex mutex (SEM_KEY_1, ACE_SV_Semaphore_Complex::ACE_CREATE, 0);
ACE_SV_Semaphore_Complex synch (SEM_KEY_2, ACE_SV_Semaphore_Complex::ACE_CREATE, 0);
+ // Perform "busy waiting" here until we acquire the semaphore. This
+ // isn't really a good design -- it's just to illustrate that you
+ // can do non-blocking acquire() calls with the ACE System V
+ // semaphore wrappers.
while (mutex.tryacquire () == -1)
if (errno == EAGAIN)
ACE_DEBUG ((LM_DEBUG, "spinning in child!\n"));