Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / APG / ThreadSafety / Tokens_Deadlock.cpp
blob80754f6768534402cb0c868d2b29b6786ad529ec
1 #include "ace/Local_Tokens.h"
2 #include "ace/Task.h"
3 #include "ace/OS_NS_unistd.h"
5 #if defined (ACE_HAS_TOKENS_LIBRARY)
7 // Listing 1 code/ch14
8 class ThreadOne : public ACE_Task_Base
10 public:
11 virtual int svc ()
13 ACE_Local_Mutex mutex1 (ACE_TEXT ("resource1"),
14 0, // Deadlock detection enabled.
15 1);// Debugging enabled.
16 mutex1.acquire ();
17 ACE_OS::sleep (2);
18 ACE_Local_Mutex mutex2 (ACE_TEXT ("resource2"), 0, 1);
19 mutex2.acquire ();
20 return 0;
24 class ThreadTwo : public ACE_Task_Base
26 public:
27 virtual int svc ()
29 ACE_Local_Mutex mutex2 (ACE_TEXT ("resource2"),
30 0, // Deadlock detection enabled.
31 1);// Debugging enabled.
32 mutex2.acquire ();
33 ACE_OS::sleep (2);
34 ACE_Local_Mutex mutex1 (ACE_TEXT ("resource1"),
35 0, // Deadlock detection enabled.
36 1);// Debugging enabled.
37 mutex1.acquire ();
38 return 0;
42 int ACE_TMAIN (int, ACE_TCHAR *[])
44 ThreadOne t1;
45 ThreadTwo t2;
47 t1.activate ();
48 ACE_OS::sleep (1);
49 t2.activate ();
50 t1.wait ();
51 t2.wait ();
53 return 0;
55 // Listing 1
57 #else /* defined (ACE_HAS_TOKENS_LIBRARY) */
59 int ACE_TMAIN (int, ACE_TCHAR *[])
61 ACE_ERROR ((LM_ERROR,
62 ACE_TEXT ("local tokens not supported ")
63 ACE_TEXT ("on this platform\n")));
64 return 0;
67 #endif /* defined (ACE_HAS_TOKENS_LIBRARY) */