[ace-users] [ace-user] ACE_Thread_Manager::wait
Douglas C. Schmidt
schmidt at dre.vanderbilt.edu
Thu Jul 12 01:31:57 CDT 2007
Hi,
Thanks for using the PRF.
> ACE VERSION: 5.5.4
Please upgrade to ACE+TAO+CIAO x.5.9 (i.e., ACE 5.5.9, TAO 1.5.9, and
CIAO 0.5.9), which you can download from
http://download.dre.vanderbilt.edu
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
http://www.dre.vanderbilt.edu/~schmidt/DOC_ROOT/ACE/docs/ACE-bug-process.html
Thus, if you need more "predictable" help for earlier versions of
ACE+TAO, I recommend that you check out
http://www.dre.vanderbilt.edu/support.html
for a list of companies that will provide you with ACE+TAO commercial
support.
> HOST MACHINE and OPERATING SYSTEM:
> Host Machine: Intel Centrio Duo 2GHz meory 1.5GB
> OS: Windows Professional SP2
>
> TARGET MACHINE and OPERATING SYSTEM: Same with Host Machine and OS
>
> THE $ACE_ROOT/ace/config.h FILE
>
> #define ACE_HAS_STANDARD_CPP_LIBRARY 1
> #define ACE_HAS_MFC 1
> #define ACE_NO_INLINE
> #include "ace/config-win32.h"
>
> AREA/CLASS/EXAMPLE AFFECTED:
> ACE_Thread_Manager
>
> DOES THE PROBLEM AFFECT:
> EXECUTION
>
> SYNOPSIS:
> ACE_Thread_Manager::wait function behavior
>
> DESCRIPTION:
> What I understand on the fuction of ACE_Thread_Manager:wait is that
> it blocks until there are no more threads running in this thread manager
> or timeout expires.
Right.
> However, it seems not working in my simple program.
>
> I spawn 10 threads in my main function.
> Each thread has its own identifier (number) assigned when the
> thread is spawned.
> With that identifier, the thread prints out its id on the screen.
>
> In the main function, just after finishing spawning all threads, I
> call the function
> ACE_Thread_Manager::wait with the timeout value of 60 seconds.
>
> What I expect is that my process will not return untile all my
> spawned threads
> are finish or 60 second-timeout expires. (I assume that 60 seconds are quite
> enough time for all the spawned threads finish their assigned job.)
>
> However, my process returnes before that.
> Please help me to understand how it happneds.
Please read the documentation on ACE_Thread_Manager::wait() and you'll
see that it takes *absolute* time, not relative time, so you'll need to
do something like this
ACE_Time_Value timeout (ACE_OS::gettimeofday () + ACE_Time_Value (60));
Thanks,
Doug
> However it is not working.
> My program is listed below.
>
>
> int main(int argc, char* argv[])
> {
> ACE::init();
> CThread *pthread[10];
> for(int i = 0; i < 10; i++)
> {
> pthread[i] = new CThread();
> pthread[i]->start(i);
> }
>
> ACE_Time_Value timeout(600);
> ACE_Thread_Manager::instance()->wait(&timeout, false, true);
>
> return 0;
> }
>
> CThread::CThread(void)
> {
> }
>
> CThread::~CThread(void)
> {
> }
>
> void* CThread::run_svc(void* arg)
> {
> Thread_Args *thread_args = ACE_static_cast(Thread_Args*, arg);
>
> ACE_Thread_Manager *tm = ACE_Thread_Manager::instance();
> ACE_thread_t me = ACE_OS::thr_self();
>
> m.acquire();
> for(int i = 0; i < thread_args->id_; i++)
> {
> cout << thread_args->id_ << "(" << i << ")" << " is running" << endl;
> }
> m.release();
>
> delete thread_args;
> return 0;
> }
>
> void CThread::start(unsigned short id)
> {
> Thread_Args *thread_args = new Thread_Args(id, this);
> m.acquire();
> cout << id << " is about to start" << endl;
> m.release();
> if(ACE_Thread_Manager::instance()->spawn((ACE_THR_FUNC)CThread::run_svc,
> ACE_static_cast(void*, thread_args), THR_DETACHED | THR_SCOPE_PROCESS)
> == -1)
> return;
> }
>
> Thanks.
> - Jeong Ho.
>
> _______________________________________________
> ace-users mailing list
> ace-users at mail.cse.wustl.edu
> http://mail.cse.wustl.edu/mailman/listinfo/ace-users
More information about the Ace-users
mailing list