summaryrefslogtreecommitdiff
path: root/tests/Thread_Manager_Test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Thread_Manager_Test.cpp')
-rw-r--r--tests/Thread_Manager_Test.cpp79
1 files changed, 27 insertions, 52 deletions
diff --git a/tests/Thread_Manager_Test.cpp b/tests/Thread_Manager_Test.cpp
index 8d1711e9f10..a739a8aa180 100644
--- a/tests/Thread_Manager_Test.cpp
+++ b/tests/Thread_Manager_Test.cpp
@@ -41,12 +41,11 @@ static u_int n_threads = ACE_MAX_THREADS;
// Helper function that looks for an existing entry in the signalled
// array. Also finds the position of the first unused entry in the
// array, and updates if requested with the t_id.
-extern "C" int
-been_signalled (const ACE_thread_t t_id,
- const u_int update = 0)
+extern "C"
+int
+been_signalled (const ACE_thread_t t_id, const u_int update = 0)
{
u_int unused_slot = n_threads;
-
for (u_int i = 0; i < n_threads; ++i)
{
if (ACE_OS::thr_equal (signalled[i], t_id))
@@ -55,8 +54,7 @@ been_signalled (const ACE_thread_t t_id,
if (update &&
unused_slot == n_threads &&
- ACE_OS::thr_equal (signalled[i],
- ACE_OS::NULL_thread))
+ ACE_OS::thr_equal (signalled[i], ACE_OS::NULL_thread))
unused_slot = i;
}
@@ -72,7 +70,8 @@ been_signalled (const ACE_thread_t t_id,
// dynamically allocated, before spawning any threads.
static ACE_Barrier *thread_start = 0;
-extern "C" void
+extern "C"
+void
handler (int /* signum */)
{
if (signalled)
@@ -91,8 +90,7 @@ worker (int iterations)
{
#if defined (VXWORKS)
ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("(%P|%t) %s: stack size is %u\n"),
- ACE_OS::thr_self (),
- ACE_OS::thr_min_stack ()));
+ ACE_OS::thr_self (), ACE_OS::thr_min_stack ()));
#endif /* VXWORKS */
#if !defined (ACE_LACKS_UNIX_SIGNALS)
@@ -156,17 +154,13 @@ main (int, ASYS_TCHAR *[])
// Dynamically allocate signalled so that we can control when it
// gets deleted. Specifically, we need to delete it before the main
// thread's TSS is cleaned up.
- ACE_NEW_RETURN (signalled,
- ACE_thread_t[n_threads],
- 1);
+ ACE_NEW_RETURN (signalled, ACE_thread_t[n_threads], 1);
// Initialize each ACE_thread_t to avoid Purify UMR's.
for (i = 0; i < n_threads; ++i)
signalled[i] = ACE_OS::NULL_thread;
// And similarly, dynamically allocate the thread_start barrier.
- ACE_NEW_RETURN (thread_start,
- ACE_Barrier (n_threads + 1),
- -1);
+ ACE_NEW_RETURN (thread_start, ACE_Barrier (n_threads + 1), -1);
// Register a signal handler.
ACE_Sig_Action sa ((ACE_SignalHandler) handler, SIGINT);
@@ -177,26 +171,18 @@ main (int, ASYS_TCHAR *[])
#if defined (VXWORKS)
// Assign thread (VxWorks task) names to test that feature.
ACE_thread_t *thread_name;
- ACE_NEW_RETURN (thread_name,
- ACE_thread_t[n_threads],
- -1);
+ ACE_NEW_RETURN (thread_name, ACE_thread_t[n_threads], -1);
// And test the ability to specify stack size.
size_t *stack_size;
- ACE_NEW_RETURN (stack_size,
- size_t[n_threads],
- -1);
+ ACE_NEW_RETURN (stack_size, size_t[n_threads], -1);
for (i = 0; i < n_threads; ++i)
{
if (i < n_threads - 1)
{
- ACE_NEW_RETURN (thread_name[i],
- char[32],
- -1);
- ACE_OS::sprintf (thread_name[i],
- ASYS_TEXT ("thread%u"),
- i);
+ ACE_NEW_RETURN (thread_name[i], char[32], -1);
+ ACE_OS::sprintf (thread_name[i], ASYS_TEXT ("thread%u"), i);
}
else
// Pass an ACE_thread_t pointer of 0 for the last thread name.
@@ -242,49 +228,39 @@ main (int, ASYS_TCHAR *[])
// group.
ACE_OS::sleep (ACE_Time_Value (1));
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("(%t) resuming group\n")));
+ ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("(%t) resuming group\n")));
if (thr_mgr->resume_grp (grp_id) == -1)
{
ACE_ASSERT (errno == ENOTSUP);
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT (" OK: resume_grp isn't supported with Pthreads\n")));
+ ACE_DEBUG((LM_DEBUG, ASYS_TEXT (" OK: resume_grp isn't supported with Pthreads\n")));
}
// Wait for 1 more second and then send a SIGINT to every thread in
// the group.
ACE_OS::sleep (ACE_Time_Value (1));
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("(%t) signaling group\n")));
+ ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("(%t) signaling group\n")));
#if defined (ACE_HAS_WTHREADS)
- thr_mgr->kill_grp (grp_id,
- SIGINT);
-#elif defined (sun)
- // thr_self () can't be used safely on Solaris within a signal
- // handler. It's not documented as being Async-Signal-Safe.
- // So, don't signal them in this test on Solaris.
+ thr_mgr->kill_grp (grp_id, SIGINT);
#elif !defined (ACE_HAS_PTHREADS_DRAFT4)
- ACE_ASSERT (thr_mgr->kill_grp (grp_id,
- SIGINT) != -1);
+ ACE_ASSERT (thr_mgr->kill_grp (grp_id, SIGINT) != -1);
#else
- if (thr_mgr->kill_grp (grp_id,
- SIGINT) == -1)
+ if (thr_mgr->kill_grp (grp_id, SIGINT) == -1)
ACE_ASSERT (errno == ENOTSUP);
#endif /* ACE_HAS_WTHREADS */
// Wait and then cancel all the threads.
ACE_OS::sleep (ACE_Time_Value (1));
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("(%t) cancelling group\n")));
+ ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("(%t) cancelling group\n")));
ACE_ASSERT (thr_mgr->cancel_grp (grp_id) != -1);
// Perform a barrier wait until all the threads have shut down.
- // But, wait for a limited time, just in case.
+ // But, wait for a limited time because sometimes the test hangs
+ // on SunOS 5.5.1 and 5.7.
const ACE_Time_Value max_wait (60);
const ACE_Time_Value wait_time (ACE_OS::gettimeofday () + max_wait);
if (thr_mgr->wait (&wait_time) == -1)
@@ -294,20 +270,19 @@ main (int, ASYS_TCHAR *[])
ASYS_TEXT ("maximum wait time of %d msec exceeded\n"),
max_wait.msec ()));
else
- ACE_ERROR ((LM_ERROR,
- "%p\n", "wait"));
+ ACE_OS::perror ("wait");
+
status = -1;
}
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("(%t) main thread finished\n")));
+ ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("(%t) main thread finished\n")));
#if defined (VXWORKS)
for (i = 0; i < n_threads - 1; ++i)
{
delete [] thread_name[i];
- // Don't delete the last thread_name, because it points to the
- // name in the TCB. It was initially 0.
+ // Don't delete the last thread_name, because it points
+ // to the name in the TCB. It was initially 0.
}
delete [] thread_name;
delete [] stack_size;