RE: GCC 4.6.2 C++ thread cancellation issue

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Not sure what happened there, but here is the corrected first program.

And your second command example is actually how our make system would have built it.  Just wasn't thinking that much about it when I threw the bug examples together :)

________________________________________
From: Jonathan Wakely [jwakely.gcc@xxxxxxxxx]
Sent: Friday, May 11, 2012 3:13 PM
To: Mike Dalpee
Cc: Ian Lance Taylor; gcc-help@xxxxxxxxxxx
Subject: Re: GCC 4.6.2 C++ thread cancellation issue

On 11 May 2012 19:41, Mike Dalpee wrote:
> Ok, I have provided the two examples as attachments.  I had to transcribe these from printouts, so I apologize if there are any typos that prevent them from immediately compiling.

Both files need
s/pthread tid;/pthread_t tid;/

For the first program I get no abort:

Thread created
In ThreadRun
In Some3rdPartyFunction
Cancelling Thread
Joining cancelled thread
Rethrowing abi::_forced_unwind
Returning from main

Did you mean to put an empty exception specification on the
Some3rdPartyFunction?

For the second I see an abort

Thread created
In ThreadRun
Handling int exception
In Some3rdPartyFunction
Cancelling Thread
Joining cancelled thread
terminate called after throwing an instance of 'int'
Aborted

> I used the following commands to build these:
>
> gcc -g bug1.cpp -o bug1 -lstdc++ -lpthread
> gcc -g bug2.cpp -o bug2 -lstdc++ -lpthread

It won't change the behaviour, but any reason you don't use these
commands instead?

g++ -g bug1.cpp -o bug1 -pthread
g++ -g bug2.cpp -o bug2 -pthread

i.e. compile with the g++ driver so libstdc++ is linked in
automatically, and use -pthread so _REENTRANT is defined, as well as
linking to libpthread.
#include <cxxabi.h>
#include <pthread.h>
#include <time.h>
#include <iostream>

using namespace std;

// abort does not occur if:
// 1) throw() is removed or
// 2) an exception is specificed (i.e., throw(some_exception))

void
Some3rdPartyFunction() throw()
{
	cout << "In Some3rdPartyFunction" << endl;

	struct timespec delay = {5,0};

	int ret =
		nanosleep(
			&delay,
			NULL);

	cout << "Returning from Some3rdPartyFunction" << endl;
}

extern "C" void*
ThreadRun(
	void* argP)
{
	cout << "In ThreadRun" << endl;

	Some3rdPartyFunction();

	cout << "Returning from ThreadRun" << endl;

	return NULL;
}

int
main(
	int   argc,
	char* argv[])
{
	pthread tid;

	int ret =
		pthread_create(
			&tid,
			NULL,
			ThreadRun,
			NULL);

	cout << "Thread created" << endl;

	struct timespec delay =  {1,0};

	ret =
		nanosleep(
			&delay,
			NULL);

	cout << "Cancelling Thread" << endl;

	ret =
		pthread_cancel(
			tid);

	void* returnValue = NULL;

	cout << "Joining cancelled thread" << endl;

	ret =
		pthread_join(
			tid,
			&returnValue);

	cout << "Returning from main" << endl;

	return 0;
}

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux