[ace-users] Questions about ACE_Thread and ACE_Thread_Adapter

Douglas C. Schmidt schmidt at dre.vanderbilt.edu
Wed Aug 15 03:08:15 CDT 2007


>Thanks so much for the detailed and timely response Doug!  

You are quite wecome.

>A few
>- The code I am working on is going into a library which will not know
>if advance if there will or will not be an ACE_Thread_Manager already
>in existence, and I don't want to conflict with it if it does already
>exist.  My short lived thread only needs to do a few tasks and then
>terminate itself.  Also, for this particular task I can't bring in the
>ACE_Task overhead, at least for now.  There is a possibility that we
>will move to the Pipes and Filter approach later on in the grand
>scheme of things, but not now.  I was rather hoping that just using
>the lower level ACE_Thread::spawn would be ok, and at least provide me
>with platform independence as we build this on several flavors of
>UNIX, linux and Win32.

I recommend not using ACE_Thread::spawn() since it is not as portable
as ACE_Thread_Manager on those platforms.

>- The example you pointed me to in Thread_Manager.cpp does not show
>how and where the Thread_Adapter will be destroyed. ??

I'm not sure what you mean.  Check out this line in the

  delete static_cast<ACE_Base_Thread_Adapter *> (thread_args);

>- even if I use an auto_ptr for the Thread_Adapter the main problem is
>that the dtor is made private, so I guess it can't be destroyed, not
>on the stack automatically, not by calling delete manually and not by
>having auto-ptr call delete automatically for me.  But maybe I am
>missing something.  I see in the Thread_Manager.cpp code that you call
>new to create and adapter, and then spawn the thread.  But I don't see
>when the thread_args gets destroyed.

Please see above.

>- Unfortunately, my $ACE_ROOT tree does not seem to have the book
>examples you mentioned (5.5.1).  Not sure why.  I see other examples.
>My ACE_ROOT is ACE_Wrappers-5.5.1, which was setup by someone else so
>I'm not sure of the exact details.

Please upgrade to ACE+TAO+CIAO x.5.10 (i.e., ACE 5.5.10, TAO 1.5.10, and
CIAO 0.5.10), which you can download from


under the heading: "Latest Beta Kit".

The DOC groups at Washington University, UC Irvine, and Vanderbilt
University only provide "best effort" support for non-sponsors for the
latest release, as described in


Thus, if you need more "predictable" help for earlier versions of
ACE+TAO, I recommend that you check out


for a list of companies that will provide you with ACE+TAO commercial

>I have been able to start a thread with ACE_Thread::spawn.  At this
>point I can pass it a static C++ method by first creating an instance
>of ACE_Thread_Adapter, which wraps around the function.  However, I
>don't know how to clean up the adapter when I'm done, and also I was
>rather hoping to call a bounded method on an object instance, which
>appears to not be possible with my compiler since I can't get the
>address of the bounded function to pass to the Thread_Adapter
>constructor.  I am trying a work around where I pass a "this" pointer
>into a static method and then call a bounded method using that
>pointer.  And it sorta seemed to work, but I get core dumps at the
>first virtual method call inside the bounded function, so not sure if
>this hack is acceptable or not.

Again, please see Chapter 9 of C++NPv1
<www.cs.wustl.edu/~schmidt/ACE/book1/> for examples.


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