phread_join problem
Artem Alimarin
alimarin@cs.kun.nl
Thu Mar 16 10:50:00 GMT 2006
Hi,
I have a problem with the small program attached below that does not do what I
expect. The program prints:
cancelling
cleanup
cancelled, joining
exception
last chance
thread is about to return
pthread_join hangs infinitely.
I expect the join to resume because the thread has exitted.
What is a problem?
The cygwin version info:
$ uname -a
CYGWIN_NT-5.2-WOW64 artem64 1.5.19(0.150/4/2) 2006-01-20 13:28 i686 Cygwin
The program compiler as:
$ g++ -o th.exe th.cpp
Thanks in advance,
Artem Alimarine
//=====================================================
#include <pthread.h>
#include <unistd.h>
#include <exception>
#include <iostream>
using namespace std;
class exit_exception {};
void cleanup_routine(void*) {
cout << "cleanup\n";
throw exit_exception();
}
void foo() {
try {
sleep(100);
}
catch(const exit_exception&) {
cout << "exception\n";
throw;
}
}
void* thread_routine(void*) {
try {
pthread_cleanup_push(cleanup_routine, NULL);
foo();
pthread_cleanup_pop(0);
}
catch(const exit_exception&) {
cout << "last chance\n";
}
cout << "thread is about to return\n";
return NULL;
}
int main() {
pthread_t the_handle;
int res;
res = pthread_create(&the_handle, NULL, thread_routine, NULL);
assert(res == 0);
sleep(1);
cout << "cancelling\n";
res = pthread_cancel(the_handle);
assert(res == 0);
cout << "cancelled, joining\n";
res = pthread_join(the_handle, NULL);
assert(res == 0);
cout << "joined\n";
pthread_detach(the_handle);
}
//=====================================================
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
More information about the Cygwin
mailing list