delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/03/16/05:50:42

X-Spam-Check-By: sourceware.org
To: cygwin AT cygwin DOT com
From: Artem Alimarin <alimarin AT cs DOT kun DOT nl>
Subject: =?utf-8?b?cGhyZWFkX2pvaW4=?= problem
Date: Thu, 16 Mar 2006 10:41:03 +0000 (UTC)
Lines: 87
Message-ID: <loom.20060316T113933-360@post.gmane.org>
Mime-Version: 1.0
User-Agent: Loom/3.14 (http://gmane.org/)
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019