Search the web
Sign In
New User? Sign Up
ace-users
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
[ace-users] Re: [ace-bugs] ACE_Task doesn't cancel thread after wor   Message List  
Reply | Forward Message #30974 of 42992 |
Hi Steffan,

>> I mean, that the thread finished and the close()-method is called. Then
>> the task falls into "passive" state.

Ok.

>> I only call activate() without giving a own thread-handler or
>> something else.

Ah, that looks like the source of your problem. You're calling
activate() without any parameters, right? In this case, the thread
that's spawned is a so-called "joinable" thread, which means that you
*must* wait/join with it or the OS won't be able to reclaim the
memory. Here's a sidebar from C++NPv2
<www.cs.wustl.edu/~schmidt/ACE/book2/> that explains what's going on:

----------------------------------------

Sidebar: Avoiding Memory Leaks When Threads Exit

The ACE_Task::activate() or the ACE_Thread_Manager spawn() and
spawn_n() methods can be passed either of the following flags:

. THR_DETACHED, which designates the spawned thread(s) as
detached so that when the thread exits the
ACE_Thread_Manager ensures the storage used for the thread's
state and exit status is reclaimed automatically.

THR_JOINABLE, which designates the spawned thread(s) as joinable so
that ACE_Thread_Manager ensures the identity and exit status of an
exiting thread is retained until another thread reaps its exit status.

The terms ``detached'' and ``joinable'' stem from the POSIX Pthreads
specification.

The default behavior for ACE_Thread_Manager (and hence ACE_Task) is to
spawn threads with the THR_JOINABLE flag. In this case, an
application must therefore call ACE_Task::wait() or
ACE_Thread_Manager::wait_task(), which wait for all joinable
threads associated with the task to exit. Likewise, an application
can call ACE_Thread_Manager::join() to wait for a designated thread to
finish and return its exit status. If none of these methods are
called, ACE and the OS won't reclaim the thread stack and exit status
of a joinable thread identifier, so the program will leak memory.

If it's inconvenient to wait for threads explicitly in your program,
you can simply pass THR_DETACHED when spawning threads or activating
tasks. Many networked application tasks and long running daemon
threads can be simplified by using detached threads. However, an
application can't wait for a detached thread to finish with
ACE_Task::wait() or obtain its exit status via join(). Applications
can use ACE_Thread_Manager::wait() to wait for all threads, both
joinable and detached, in an ACE_Thread_Manager to finish.

----------------------------------------

Take care,

Doug
--
Dr. Douglas C. Schmidt, Associate Professor TEL: (949) 824-1901
Dept of Electrical & Computer Engineering FAX: (949) 824-2321
616E Engineering Tower WEB: www.ece.uci.edu/~schmidt/
University of California, Irvine, 92697-2625 NET: schmidt@...



Wed May 15, 2002 1:51 pm

schmidt@...
Send Email Send Email

Forward
Message #30974 of 42992 |
Expand Messages Author Sort by Date

Hi Steffan, ... Ok. ... Ah, that looks like the source of your problem. You're calling activate() without any parameters, right? In this case, the thread ...
Douglas C. Schmidt
schmidt@...
Send Email
May 15, 2002
1:54 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help