Modify

Opened 16 years ago

Closed 12 years ago

#81 closed Bugs (Out of Date)

AIX 4.3 SIGSEGV at thread termination

Reported by: cpqlvc Owned by: Roland Schwarz
Milestone: Component: threads
Version: None Severity:
Keywords: Cc:

Description

Under AIX 4.3 / gcc 2.95.3 the threads library gets a 
segmentation fault when a thread terminates.  This 
error seems to be related to the parameter that's 
supplied to the thread consturctor.  If the parameter 
is a functor, a segmentation fault occurs.  If the 
parameter is the address of a function, the threads 
terminate normally.

For example the tennis program, which pass a 
thread_adapter function object to the thread 
constructor, gets a segmentation fault.  Here's the 
last few lines of its output.

PLAYER-A: Play.
PLAYER-B: Play.
PLAYER-A: Play.
PLAYER-B: Play.
PLAYER-A: Play.
PLAYER-B: Play.
PLAYER-A: Play.
---Noise OFF...
PLAYER-B: Gone.
PLAYER-A: Gone.
Segmentation fault (core dumped)
(/home/swansond/Boost)$ 


In contrast the exemple program from the condition 
variable documentation, which passes the address of a 
function to the thread constructor, works fine.  
Here's the last few lines of its output.

sent: 96
sent: 97
received: 96
received: 97
sent: 98
sent: 99
received: 98
received: 99
received: -1
(/home/swansond/Boost)$ 


To further characterize this problem, I wrote two 
small programs, one that passes a functor and one that 
passes the address of a global function, but otherwise 
these two programs do the same (trivial) thing.  The 
former fails while the latter runs normally.  I 
enclose both programs.

--- Uses functor and gets segmentation fault
#include <iostream>
#include <cstddef>
#include <cstdlib>
#include <cassert>

#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>

typedef boost::mutex::scoped_lock   Lock;
typedef boost::mutex                Mutex;

class Functor
{
public:
    Functor(Mutex& m, int instance) : m_mutex(m), 
m_instance(instance) {}
    void operator()();
    virtual ~Functor(){}
private:
    Mutex&  m_mutex;
    int     m_instance;
};


void
Functor::operator()()
{
    for (int i=0; i<10; i++) {
        {
            Lock    lck(m_mutex);
            std::cout << "Thread" << m_instance << " 
says hello!" << std::endl;
        }
        boost::thread::yield();
    }
}

int
main()
{
    Mutex   mtx;

    Functor     one(mtx, 1);
    Functor     two(mtx, 2);

    boost::thread   thrd1(one);
    boost::thread   thrd2(two);

    thrd1.join();
    thrd2.join();

    return EXIT_SUCCESS;
}

--- Uses addres of global function and terminates 
normally
#include <iostream>
#include <cstddef>
#include <cstdlib>
#include <cassert>

#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>

typedef boost::mutex::scoped_lock   Lock;
typedef boost::mutex                Mutex;

Mutex m_mutex;

void one()
{
    for (int i=0; i<10; i++) {
        {
            Lock    lck(m_mutex);
            std::cout << "Thread1 says hello!" << 
std::endl;
        }
        boost::thread::yield();
    }
}

void two()
{
    for (int i=0; i<10; i++) {
        {
            Lock    lck(m_mutex);
            std::cout << "Thread2 says hello!" << 
std::endl;
        }
        boost::thread::yield();
    }
}

int
main()
{
    Mutex   mtx;

    boost::thread   thrd1(&one);
    boost::thread   thrd2(&two);

    thrd1.join();
    thrd2.join();

    return EXIT_SUCCESS;
}

Attachments (0)

Change History (1)

comment:1 Changed 12 years ago by Roland Schwarz

Status: assignedclosed
Logged In: YES 
user_id=541730

This is a dated bug report.
I tried to run this on linux i386, boost RC_1_34 sucessfully
(no segfault).
I could not observe the problem.
I also could not contact the submitter to ask if this bug
still applies.
If anyone still see a problem, please reopen the bug.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Roland Schwarz.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.