Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / examples / Shared_Memory / test_SV.cpp
blobac20d33e93a21e7dfe6a82a8c1ad5c57f9b6752d
1 #include "ace/Shared_Memory_SV.h"
2 #include "ace/Log_Msg.h"
3 #include "ace/OS_NS_unistd.h"
5 #define SHMSZ 27
6 #define SHM_KEY (key_t) 5678
8 static void
9 client ()
11 ACE_Shared_Memory_SV shm_client (SHM_KEY, SHMSZ);
12 char *shm = (char *) shm_client.malloc ();
14 for (char *s = shm; *s != '\0'; s++)
15 putchar (*s);
17 putchar ('\n');
18 *shm = '*';
21 static void
22 server ()
24 ACE_Shared_Memory_SV shm_server (SHM_KEY,
25 SHMSZ,
26 ACE_Shared_Memory_SV::ACE_CREATE);
27 char *shm = (char *) shm_server.malloc ();
28 char *s = shm;
30 for (char c = 'a'; c <= 'z'; c++)
31 *s++ = c;
33 *s = '\0';
35 while (*shm != '*')
36 ACE_OS::sleep (1);
38 if (shm_server.remove () < 0)
39 ACE_ERROR ((LM_ERROR, "%p\n", "remove"));
42 int
43 ACE_TMAIN (int, ACE_TCHAR *[])
45 switch (ACE_OS::fork ())
47 case -1:
48 ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "fork"), 1);
49 case 0:
50 // Make sure the server starts up first.
51 ACE_OS::sleep (1);
52 client ();
53 break;
54 default:
55 server ();
56 break;
59 return 0;