[ace-users] [quesion] on ACE_Thread_Manager
Douglas C. Schmidt
schmidt at dre.vanderbilt.edu
Wed Jul 11 04:33:15 CDT 2007
Hi,
> Thanks for your quick reply
You are welcome. BTW, please make sure to send all questions related to
TAO or ACE to the ACE mailing list or ACE+TAO newsgroup, rather than to
me directly since I travel frequently and often don't have ready access
to email.
> Even though I initialize ACE as you recommand by rewritting my main function,
> I have the same problem.
Right - that's because your main() function is returning after starting
all the threads.. You need to wait() for the threads to exit before you
return from main(). Please see Chapter 9 of C++NPv2
<www.cs.wustl.edu/~schmidt/ACE/book2> for more details.
Thanks,
Doug
> // testthread.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다.
> //
>
> #include "stdafx.h"
> #include "ace/Init_ACE.h"
> #include "Thread.h"
>
> int main(int argc, char* argv[])
> {
> ACE::init();
> CThread thread;
> thread.start(10);
> /* for(int i = 0; i < 100; i++)
> {
> pthread[i] = new CThread();
> pthread[i]->run(i);
> }
>
> */
> ACE::fini();
> return 0;
> }
>
>
>
> On 7/11/07, Douglas C. Schmidt <schmidt at dre.vanderbilt.edu> wrote:
> >
> > Hi Jeong,
> >
> > 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:
> > > occurrance of excpetion on the function callled
> > > "thread_mutex_lock" in the file
> > > of os_ns_thread.inl
> > >
> > > DESCRIPTION:
> > > When executing my simple program based on ACE_Thread_Manager,
> > > an exception occures at the marked point:
> > >
> > > ACE_INLINE int
> > > ACE_OS::thread_mutex_lock (ACE_thread_mutex_t *m)
> > > {
> > > // ACE_OS_TRACE ("ACE_OS::thread_mutex_lock");
> > > #if defined (ACE_HAS_THREADS)
> > > # if defined (ACE_HAS_WTHREADS)
> >
> > Have you made sure to initialize ACE by calling ACE::init() at the start
> > of your main() function?
> >
> > Thanks,
> >
> > Doug
> >
> > > -> ::EnterCriticalSection (m);
> > > return 0;
> > > # elif defined (ACE_HAS_STHREADS) || defined (ACE_HAS_PTHREADS)
> > > || defined (ACE_VXWORKS)
> > > return ACE_OS::mutex_lock (m);
> > >
> > > my simple program as followed
> > > testthread.cpp
> > > #include "stdafx.h"
> > > #include "Thread.h"
> > >
> > > int main(int argc, char* argv[])
> > > {
> > > CThread thread;
> > > thread.start(10);
> > > return 0;
> > > }
> > >
> > > thread.h
> > > #pragma once
> > >
> > > class CThread
> > > {
> > > public:
> > > CThread(void);
> > > public:
> > > ~CThread(void);
> > >
> > > private:
> > > struct Thread_Args
> > > {
> > > public:
> > > Thread_Args(/*unsigned short id,*/ CThread* lsp) :
> > > /*id_(id),*/ this_(lsp) {}
> > > CThread* this_;
> > > // unsigned short id_;
> > > };
> > >
> > > static void* run_svc (void* arg);
> > >
> > > public:
> > > void start(unsigned short);
> > > };
> > >
> > > thread.cpp
> > > #include "StdAfx.h"
> > > #include "Thread.h"
> > > #include <iostream>
> > >
> > > #include "ace/Basic_Types.h"
> > > #include "ace/Thread_Manager.h"
> > > #include "ace/Log_Msg.h"
> > >
> > > using namespace std;
> > >
> > > CThread::CThread(void)
> > > {
> > > }
> > >
> > > CThread::~CThread(void)
> > > {
> > > }
> > >
> > > void* CThread::run_svc(void* arg)
> > > {
> > > while(1)
> > > {
> > > cout << "1" << endl;
> > > }
> > > /*
> > > // Thread_Args *thread_args = ACE_static_cast(Thread_Args*, arg);
> > >
> > >
> > >
> > > // for(int i = 0; i < thread_args->id_; i++)
> > > // cout << thread_args->id_ << " is running" << endl;
> > >
> > > // delete thread_args;
> > > */
> > > return 0;
> > > }
> > >
> > > void CThread::start(unsigned short id)
> > > {
> > > Thread_Args *thread_args = new Thread_Args(/*id,*/ this);
> > > 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;
> > > }
> > >
> > > _______________________________________________
> > > 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