Boost logo

Boost Users :

From: Kutch, Patrick G (patrick.g.kutch_at_[hidden])
Date: 2004-02-11 11:07:13


Looking at the code, by 1st guess would be that you have a race
condition. tObj->runthread() is getting executed before
tObj->createthead() has finished its business and the worker thread has
actually entered the mutex.

Meaning that tObj->runthread() calls the notify_one() BEFORE the actual
worker thread does a wait. Thus when your threadproc does a lock and
then a wait, it will wait forever because nothing will do the
notify_one() again.

Race conditions are funny things, may work perfectly on one box forever,
then change one line of code, or take it to another system and bad
things happen. May also behave differently under different OS's -
mutexes are a prime examle of this, under Windows they seem to be
recursive by default, but not under LINUX.

A down and dirty way to see if my theory is correct, put in a delay
between the tObj->createthread() and tObj->runthread() lines.

Hope this helps - if it does praise me with thanx, if it doesn't it was
a crackpot theory or I haven't had sufficient coffee yet to make an
intelligent analysis - you pick. :-)

good luck,

- Patrick

 

-----Original Message-----
From: boost-users-bounces_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] On Behalf Of Michael
Glassford
Sent: Wednesday, February 11, 2004 7:40 AM
To: Boost Users mailing list
Subject: [Boost-users] Re: Re: Thread creation state

What I meant was, can you post a complete sample that you have actually
compiled and run and that has actually demonstrated the problem? That
obviously isn't the case with the code you posted because it contains
syntax
errors and the main() function in your second post doesn't match the
definition of the testCommand class in your first post.

Having said that, I fixed the errors the best I could and don't see the
problem. It would help if you could:

1) Tell me what compiler and compiler version you're using.
2) Tell me what Boost version you're using.
3) Post a complete code sample that demonstrates the problem.
4) Specify what compile and link options you're using (perhaps you could
attach a make file or project file?)

Sorry; I'm trying to help, but if you want me to be able to figure out
the
problem you'll have to help me out.

Mike

----- Original Message -----
From: <janardhan.guptha_at_[hidden]>
Newsgroups: gmane.comp.lib.boost.user
Sent: Tuesday, February 10, 2004 11:32 PM
Subject: RE: Re: Thread creation state

>
> The rest of the applicatin is just creating the object and preparing
it
> for execution. I am using Win32 version of boost.Thread
implementation.
>
> The creation code snipet is
>
> void main() {
> testCommand *tObj = new testCommand(11);
> tObj->createthread();
> tObj->runthread();
> }
>
>
> -----Original Message-----
> From: boost-users-bounces_at_[hidden]
> [mailto:boost-users-bounces_at_[hidden]]On Behalf Of Michael
> Glassford
> Sent: Wednesday, February 11, 2004 12:17 AM
> To: boost-users_at_[hidden]
> Subject: [Boost-users] Re: Thread creation state
>
>
> It would be a lot easier to help if you could post a complete,
> compilable example that demonstrates the problem. Also, it would be
> useful to know whether you are using the Win32, pthread, or Mac
> implementation of Boost.Thread.
>
> Thanks,
>
> Mike
>
>
> <janardhan.guptha_at_[hidden]> wrote in message
> news:433CFA26BCA852438922F929E3D07955AE53A7_at_blraddc02.efi.internal...
> > I am creating a boost thread, how to know in which state it is
> created.
> > I have a code snippet that is waiting always in the thread creatin
> functon
> > istelf. Where as i tried with some boost samples, they are working
> amazingly
> > perfect. This is how my code snippet looks like
> >
> > typedef boost::mutex::scoped_lock lock;
> > class testCommand {
> > static void threadfunc() {
> > testCommand *testObj = mMapCommand[mObjID];
> > testObj->processthread();
> > };
> >
> > static map< int mObjID, testCommand*> mMapCommand;
> > private:
> > void createthread() {
> > mThread = new boost::thread(&testCommand::threadfunc);
> > }
> > void processthread() {
> > lock lk(mMutex);
> > mCondition.wait(lk);
> > //// Some Action
> > };
> >
> > void runthread() {
> > lock lk(mMutex);
> > mCondition.notify_one();
> > };
> >
> > public:
> > static int mObjID;
> > boost::thread *mThread;
> > boost::condition mCondition;
> > boost::mutex mMutex;
> > };
> >
> >
> > The newly created thread is waiting at the following location
> forever, by
> > the time
> > i get a chance to execute the new thread is greatly delayed.
> >
> > NTDLL! 77f8856e()
> > boost::detail::thread::lock_ops<boost::mutex>::unlock(boost::mutex &
> {...})
> > line 49
> > boost::detail::thread::scoped_lock<boost::mutex>::unlock() line 85 +
> 11
> > bytes
> >
> boost::detail::thread::scoped_lock<boost::mutex>::~scoped_lock<boost::
> mutex>
> > () line 74
> > `anonymous namespace'::thread_param::started() line 47 + 15 bytes
> > thread_proxy(void * 0x0012fd74) line 71
> > _threadstartex(void * 0x00961040) line 212 + 13 bytes
> > KERNEL32! 7c57b382()
> >
> > It sounds like i am missing something here. The queries here are
> > 1. why it is waiting at the above specified line forever ?
> > 2. Where can i get few worth thread samples done using boost::thread
> >
> > Regards
> > Janardhan
>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net