Opened 20 years ago
Closed 17 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; }
Note:
See TracTickets
for help on using tickets.