RE: GCC 4.6.2 C++ thread cancellation issue

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

 



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.

I used the following commands to build these:

gcc -g bug1.cpp -o bug1 -lstdc++ -lpthread
gcc -g bug2.cpp -o bug2 -lstdc++ -lpthread

Let me know if you have any problems getting them built.
________________________________________
From: Ian Lance Taylor [iant@xxxxxxxxxx]
Sent: Thursday, May 10, 2012 3:10 PM
To: Mike Dalpee
Cc: gcc-help@xxxxxxxxxxx
Subject: Re: GCC 4.6.2 C++ thread cancellation issue

Mike Dalpee <mikedalpee@xxxxxxxxxxxx> writes:

> I was able to create some small test cases that demonstrate the
> problem.  Unfortunately, the computers I used to do this have no
> internet access and I am not allowed to take media out of the
> building. I will try to get a printout I can scan or type in, but in
> the meantime, here are the salient features of the test cases.

Wow, that is really something.  Unfortunately my experience with trying
to create a test case from a text description is almost uniformly
negative, in that there always seems to be some key element that is
obvious to the reporter but not to me.  Anybody out there want to try to
recreate this?

Ian
#include <cxxabi.h>
#include <pthread.h>
#include <time.h>
#include <iostream>

using namespace std;

// abort does not occur if the catch/rethrow
// of abi::__forced_unwind is removed

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

	try
	{
	
		struct timespec delay = {5,0};

		int ret =
			nanosleep(
				&delay,
				NULL);
	}
	catch (abi::__forced_unwind&)
	{
		cout << "Rethrowing abi::_forced_unwind" << endl;

		throw;
	}

	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;
}
#include <cxxabi.h>
#include <pthread.h>
#include <time.h>
#include <iostream>

using namespace std;

// abort does not occur if the catch/rethrow
// of abi::__forced_unwind is removed

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

	try
	{
	
		struct timespec delay = {5,0};

		int ret =
			nanosleep(
				&delay,
				NULL);
	}
	catch (abi::__forced_unwind&)
	{
		cout << "Rethrowing abi::_forced_unwind" << endl;

		throw;
	}

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

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

	try
	{
		throw 1;
	}
	catch (int&)
	{
		cout << "Handling int exception" << 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