[ace-users] Questions about ACE_Thread and ACE_Thread_Adapter

Douglas C. Schmidt schmidt at dre.vanderbilt.edu
Tue Aug 14 02:54:54 CDT 2007


>Hi everyone.  ACE newbie here.

Welcome!  To ensure that we have proper version/platform/compiler
information, please make sure you fill out the appropriate problem
report form (PRF), which is in


or in


in older versions of ACE+TAO.  Make sure to include this information
when asking any questions about ACE+TAO since otherwise we have to
"guess" what version/platform/compiler/options you've using, which is
very error-prone and slows down our responsiveness.

> Anyone know where I can find some example code showing the correct
> usage of ACE_Thread_Adapter to spawn a detached thread with
> ACE_Thread::spawn() that will call a member method on an object
> instance?  Is that even possible?

Sure - there's an example in ACE_ROOT/ace/Thread_Manager.cpp.  Just
search for ACE_Thread_Adapter.

> I sorta crippled something together, but I have a feeling I am doing
> something wrong?  I gathered that I could not instantiate an instance
> of ACE_Thread_Adapter on the stack because the dtor is private.

That's correct.

> I can create one with new, but then there is a leak because I can't
> call delete against it.  I must not be using this Command class
> correctly.

The trick to avoiding a memory leak is to use an auto_ptr.  Please see
Chapter 9 of C++NPv1 <www.cs.wustl.edu/~schmidt/ACE/book1> for an
example of how to use something like the ACE_Thread_Adapter, which is
called Thread_Args.  The examples is also in


However, I recommend you use the ACE_Task rather than the
ACE_Thread_Adapter since it hides all of this stuff from you!  Please
see Chapter 6 of C++NPv2 <www.cs.wustl.edu/~schmidt/ACE/book2/> for


Dr. Douglas C. Schmidt                       Professor and Associate Chair
Electrical Engineering and Computer Science  TEL: (615) 343-8197
Vanderbilt University                        WEB: www.dre.vanderbilt.edu/~schmidt
Nashville, TN 37203                          NET: d.schmidt at vanderbilt.edu

More information about the Ace-users mailing list