|
Boost : |
From: Yakov Bachmutsky (yakov_at_[hidden])
Date: 2002-10-29 10:28:05
----- Original Message -----
From: "William E. Kempf" <wekempf_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Tuesday, October 29, 2002 3:17 PM
Subject: Re: [boost] Re: new libraries proposal
>
> Yakov Bachmutsky said:
> >
> > ----- Original Message -----
> > From: "Dirk Gerrits" <dirk_at_[hidden]>
> > To: <boost_at_[hidden]>
> > Sent: Monday, October 28, 2002 7:32 PM
> > Subject: [boost] Re: new libraries proposal
> >
> >
> >> Yakov Bachmutsky wrote:
> >>
> >> > Hi,
> >> >
> >> > After a long break I'd like to take a little part in boost.
> >>
> >> [snip]
> >>
> >> > 3. A thread library that is related to the sync lib but can be
> >> detached. Contains mainly a thread wrapper class that may be
> >> inharited or used as is.
> >> > Contains also thread factory class and such.
> >>
> >> There is already a thread library in Boost. Does your proposal offer
> >> anything significantly different than that one?
> >
> > Mine is windows oriented.
> > On a second thought, it would be better to add stuff to the existing
> > one. What I have in addition to the existing is:
> > 1. onException() called from ThreadProc (=threadproxy) to let the user
> > decide what to do with it.
>
> Hot topic, but I don't see how this adds much utility. Maybe I'm just not
> fully understanding you. Care to elaborate?
static DWORD WINAPI CThread::ThreadProc(LPVOID pv)
{
CThread *pThread = (CThread*)pv;
do
{
try
{
// startup
if( !pThread->OnStartup() )
break;
// run
pThread->m_dwExitCode = pThread->Run();
// cleanup
pThread->OnCleanup();
break;
}
catch(...)
{
}
if( !pThread->OnException() )
/*****************************************/
{
pThread->OnCleanup();
break;
}
}
while(true);
return pThread->m_dwExitCode;
}
// this function can be overriden to support other styles like class member
functions.
DWORD CThread::Run()
{
return (m_pHandler) (m_pParams);
}
>
> > 2. since in windows threads are also sync objects, I can wait for a
> > thread in my standard locks:
> > lock _lock(my_thread, my_event)
>
> Actually of limited utility, and very difficult to do portably. Not
> likely to be added to Boost.Threads.
>
> > 3. I use it to thread-run class member functions via a class inheriting
> > CThread.
>
> Actually a non-issue with Boost.Threads. I'm developing a large set of
> tutorials that will include examples of how to accomplish this with
> Boost.Threads, and to my mind the result is cleaner, more efficient, and
> just as easy to code as the inheritance based approach. At it's simplest:
>
> class MyThread
> {
> public:
> MyThread() : m_thread(boost::bind(&MyThread::run, this)) { }
> void run() { }
> private:
> boost::thread m_thread;
> };
>
> I'd be very happy to discuss any of this though.
Very nice !
The only thing I haven't mention yet, and I guess its no much interest as
well, is that my threads have names(std::string)
I'm just a fun of neat logs and so my thread class also logs that it
started, ended and so on with its name inside.
>
> --
> William E. Kempf
>
>
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk