1 #include "test_config.h"
2 #include "ace/Log_Msg.h"
6 #ifdef ACE_HAS_PTHREADS
8 #endif /* ACE_HAS_PTHREADS */
10 #if !defined (ACE_HAS_THREADS) || defined (ACE_LACKS_IOSTREAM_TOTALLY)
11 int run_main (int, ACE_TCHAR
*[])
13 ACE_START_TEST (ACE_TEXT ("Log_Thread_Inheritance_Test"));
19 #ifdef ACE_HAS_PTHREADS
20 struct Inheritor
: ACE_Task_Base
24 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) - this test might crash ACE if it does not "
25 "have the fix for the second bug in #3480.\n"));
31 void* spawn_ace_task (void*)
35 inheritor
.activate ();
41 bool test_inherited_attributes ()
43 // This test verifies ACE_OS_Log_Msg_Attributes correctly initializes
44 // when an ACE thread is created from a non-ACE thread (i.e. pthreads)
45 // and is then used for logging.
47 // This test will cause occasional SEGVs on failure.
48 // stallions 2009/02/05
51 if (pthread_create (&parent
, 0, spawn_ace_task
, 0) != 0)
55 pthread_join (parent
, 0);
59 #endif /* ACE_HAS_PTHREADS */
61 struct MyThread
: ACE_Task_Base
63 enum { THREAD_DEFAULTS
= THR_NEW_LWP
|THR_JOINABLE
|THR_INHERIT_SCHED
};
65 explicit MyThread (bool openfile
= false)
66 : openfile_ (openfile
) {}
69 static MyThread childthread_
;
75 ACE_LOG_MSG
->msg_ostream (
77 ACE_TEXT_ALWAYS_CHAR (
79 ACE_TEXT ("Log_Thread_Inheritance_Ostream")
83 ACE_LOG_MSG
->set_flags (ACE_Log_Msg::OSTREAM
);
84 ACE_LOG_MSG
->clr_flags (ACE_Log_Msg::STDERR
| ACE_Log_Msg::LOGGER
);
85 MyThread ends_first_thread
;
86 ends_first_thread
.activate (THREAD_DEFAULTS
, 10);
87 ends_first_thread
.wait ();
88 childthread_
.activate (THREAD_DEFAULTS
, 10);
90 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) - in svc() openfile_ is %C\n",
91 (openfile_
? "true" : "false")));
94 for (int i
= 0; i
< 100; ++i
)
96 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) - loop %d\n", i
));
97 if (!(i
% 10)) ACE_OS::thr_yield ();
104 MyThread
MyThread::childthread_
;
106 int run_main (int, ACE_TCHAR
*[])
108 ACE_START_TEST (ACE_TEXT ("Log_Thread_Inheritance_Test"));
109 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) - in run_main()\n"));
110 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) - this test will crash ACE if it does not "
111 "have the fix for bug #3480.\n"));
112 ACE_OSTREAM_TYPE
*initial_stream
= ACE_LOG_MSG
->msg_ostream ();
116 MyThread::childthread_
.wait ();
117 ACE_LOG_MSG
->msg_ostream (initial_stream
, 0);
118 #ifdef ACE_HAS_PTHREADS
119 if (!test_inherited_attributes ()) return -1;
120 #endif /* ACE_HAS_PTHREADS */
121 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) - Test passed.\n"));