Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / tests / Task_Wait_Test.cpp
blob0638e66ffaebf9ddf768f26131ea6b9e210606d3
1 //=============================================================================
2 /**
3 * @file Task_Wait_Test.cpp
5 * This program tests the ACE_Thread_Manager::wait() from a called-back
6 * ACE_Task::close() on thread exit.
8 * @author Steve Huston <shuston@riverace.com>
9 */
10 //=============================================================================
13 #include "test_config.h"
14 #include "ace/Event.h"
15 #include "ace/Thread_Manager.h"
16 #include "ace/Task.h"
17 #include "ace/OS_NS_unistd.h"
19 // On Windows, this test will deadlock because a thread tries to join with
20 // itself. Pthreads, et al, have deadlock protection in join; Windows Vista
21 // and Server 2003 have API to access the info needed to check for deadlock
22 // in ACE_OS::thr_join() - don't run this test on earlier Windows versions
23 // because it will hang/time out and there's little to be done about it.
24 #if defined (ACE_HAS_THREADS) && ((defined (_WIN32_WINNT) && (_WIN32_WINNT >= 0x0502)) || !defined (WIN32))
25 # define RUN_THIS_TEST
26 #endif
28 #ifdef RUN_THIS_TEST
30 static ACE_Event TaskDone;
32 // Define a ACE_Task that does little except exit and try to clean up.
34 class Do_Nothing_Task : public ACE_Task_Base {
35 public:
36 int close (u_long flags = 0) override;
38 int svc () override;
41 // close tries to wait for other threads. There aren't any, but as long as
42 // we don't deadlock, it's good.
43 int
44 Do_Nothing_Task::close (u_long)
46 ACE_DEBUG ((LM_DEBUG,
47 ACE_TEXT ("Task 0x%x, thread %t closing\n"),
48 this));
49 this->wait ();
50 TaskDone.signal ();
51 return 0;
55 // svc just waits a second then exits.
56 int
57 Do_Nothing_Task::svc ()
59 ACE_DEBUG ((LM_DEBUG,
60 ACE_TEXT ("Task 0x%x, thread %t waiting to exit\n"),
61 this));
62 ACE_OS::sleep (1);
64 return 0;
67 #endif /* RUN_THIS_TEST */
69 int
70 run_main (int, ACE_TCHAR *[])
72 ACE_START_TEST (ACE_TEXT ("Task_Wait_Test"));
73 int status = 0;
75 #if defined (RUN_THIS_TEST)
77 Do_Nothing_Task t;
78 status = t.activate ();
79 TaskDone.wait();
81 #else
82 ACE_ERROR ((LM_INFO,
83 ACE_TEXT ("inadequate thread support on this platform\n")));
84 #endif /* RUN_THIS_TEST */
86 ACE_END_TEST;
87 return status;