Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.
Bug 160638 - pthread_cancel() crashes application.
Summary: pthread_cancel() crashes application.
Alias: None
Product: Red Hat Enterprise Linux 3
Classification: Red Hat
Component: gcc
Version: 3.0
Hardware: i686
OS: Linux
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
Depends On:
TreeView+ depends on / blocked
Reported: 2005-06-16 08:35 UTC by Raj Devanesan
Modified: 2007-11-30 22:07 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2005-06-16 08:43:48 UTC
Target Upstream Version:

Attachments (Terms of Use)

Description Raj Devanesan 2005-06-16 08:35:26 UTC
Description of problem:

Calling pthread_cancel crashes the application, and core dumps. Same 
application build for previous versions of LINUX or solaris works fine. Any 
suggestions / details regarding this issue will be very helpful. At this point 
we are not able to move forward with AS 3.0 migration. 

While talking to my counterparts in NY, I found out that using /opt/gcc/... has 
some problems, so they recommended to use /usr/bin/g++. That solved the FATAL 
ERROR exception not rethrown error which I got earlier. But the crash still 

Following is the code extract of the MsgThread class which wraps the thread_t 
and uses POSIX trhead funtions. 

#ifndef __MSG_THREAD_H__
#define __MSG_THREAD_H__

#include <pthread.h>
#include "MsgRunnable.h"
#include "MsgException.h"

 *  A wrapper for pthread functions.
 *  <pre>
 *  Date        Developer    Description
 *  ----------  -----------  --------------------------------------------------
 *  2001/08/06  nshibuya     created.
 *  </pre>
class MsgThread
   * A thread is not alive before it is started.
  MsgThread() : _isAlive( false ) {}

   * This starts a new thread and invokes the runnable instance.
   * @param runnable an implementation of the MsgRunnable interface.
   * @exception MsgException if fails to start a new thread.
  void start( MsgRunnable* runnable, pthread_attr_t* attr = NULL ) throw 

   * This stops the thread.
  void stop() throw (MsgException);

   * This returns the thread alive status.
   * @return true if the thread still alive.
  msg_bool alive() const { return _isAlive; }  

   * A pthread variable.
  pthread_t _thread;

   * An alive flag.
  msg_bool _isAlive;


include "common/MsgThread.h"
#include "common/MsgLog.h"

// thread 
function //=====================================================================
extern "C" void* loop( void* data )
  MsgRunnable* runnable = (MsgRunnable*)data;

  catch( MsgException& ex )
  catch( ... )
    ERROR( "An unhandled error was thrown to the thread loop function" );

  return NULL;

// start a thread 
void MsgThread::start( MsgRunnable* runnable, pthread_attr_t* attr ) throw 
(MsgException) {
  _isAlive = true;

  int error = pthread_create( &_thread, attr, loop, runnable );

  if( error )
    THROW( "Failed to create a thread: error=" << error );

// stop the 
thread //=======================================================================
void MsgThread::stop() throw (MsgException)
  _isAlive = false;

  int error = pthread_cancel( _thread );

  if( error )
    THROW( "Failed to cancel the thread: error=" << error );

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
Actual results:

Expected results:

Additional info:

Comment 1 Jakub Jelinek 2005-06-16 08:43:48 UTC
You can't use catch (...) if you want cancellation to work (or you must
disable cancellation before the try block with catch (...) and reenable
it afterwards.
catch (...) blocks the cancellation.
There has been effort to resolve this, but because of the lack of standardization
of POSIX threads and C++ coexistence and because some C++ people insist that
catch (...) must also catch thread cancellation, while POSIX requires that
once cancellation starts, it must not be discarded, this resolving is currently
deadlocked.  If the POSIX and C++ committees ever sit together and decide what
the behaviour should be, this will change, but until then enabled thread
cancellation and catch (...) are incompatible.

Note You need to log in before you can comment on or make changes to this bug.