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