[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bug: Spawning short-lived threads may crash the memory allocator
From: |
Wolfram Gloger |
Subject: |
Re: Bug: Spawning short-lived threads may crash the memory allocator |
Date: |
1 Nov 2001 12:11:27 -0000 |
Hello,
> We like to report a bug we call "Spawning short-lived threads may crash the
> memory allocator".
> The bug most probably resides in pthreads.
Sorry, but it's in your program.
> Main part of the memtester program:
>
> class TSecondThread : public TDetachThread{
> private:
> TBinarySignal* Signal;
> char MemoryBlock[TEST_BLOCK_SIZE];
> protected:
> // Overloads pure virtual function in base class.
> virtual void Execute() throw ();
> public:
> TSecondThread(TBinarySignal& signal);
> };
>
> TSecondThread::TSecondThread(TBinarySignal& signal){
> Signal = &signal;
> }
>
> void TSecondThread::Execute() throw (){
> TBinarySignal* s = Signal;
> delete this;
Here is the problem. "delete this" is almost always suspicious. Here
you are implicitly deallocating the space for the pthread_t descriptor
in your base class TDetachThread. Note that pthread_create() does
_not_ guarantee that the setting of the pthread_t descriptor occurs
before the thread actually starts running. Hence the pthread_create()
call in your TDetachThread::Dispatch() method can (and sometimes does)
crash when it finally tries to write the pthread_t descriptor value.
You could for example delete your TSecondThread from the main loop
rather than from the thread itself, then the problem does not occur.
alternatively, make the pthread_t variable local to
TDetachThread::Start().
Regards,
Wolfram.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: Bug: Spawning short-lived threads may crash the memory allocator,
Wolfram Gloger <=