From: Romano Paolo Tenca <rotenca@telvia.it>
To: Pthreads-Win32 list <pthreads-win32@sources.redhat.com>
Subject: pthread_cond_destroy and cancel
Date: Mon, 12 Jun 2006 12:27:00 -0000 [thread overview]
Message-ID: <448D5D96.4070902@telvia.it> (raw)
This code creates a thread and use 2 cond var to sincronize.
Then the thread is cancelled and the thread hangs executing
pthread_cond_destroy(&cv2).
The output is
main: sleeping forever
thread: try to destroy cv2
Where is the problem? In my code or in pthread_cond_destroy with a
deferred cancel pending?
----------------------------start of code --------------------------
#include <windows.h>
#include <stdio.h>
#include <pthread.h>
#include <assert.h>
/*
* compiled with gcc version 3.2.3 (mingw special 20030504-1)
* under XP Professional
* linked with libpthreadGC2 2.7.0 prebuilt
*/
static pthread_cond_t cv1 =
PTHREAD_COND_INITIALIZER;
static pthread_mutex_t mutex1 =
PTHREAD_ERRORCHECK_MUTEX_INITIALIZER;
static pthread_cond_t cv2 =
PTHREAD_COND_INITIALIZER;
static pthread_mutex_t mutex2 =
PTHREAD_ERRORCHECK_MUTEX_INITIALIZER;
static void *func(void *arg){
int err;
// signal cv1
pthread_mutex_lock(&mutex1);
pthread_cond_signal(&cv1);
pthread_mutex_lock(&mutex2);
pthread_mutex_unlock(&mutex1);
// wait cv2
pthread_cond_wait(&cv2, &mutex2);
pthread_mutex_unlock(&mutex2);
// to be sure that main calls cancel on this thread
Sleep(50);
//destroy mutex2 and cv2
printf("thread: try to destroy cv2\n");
err = pthread_cond_destroy(&cv2);
printf("thread: cv2 err: %d\n",err); // bug? this is not executed
pthread_mutex_destroy(&mutex2);
return NULL;
}
void test(void){
int err;
pthread_t pid;
pthread_mutex_lock(&mutex1);
// create thread
pthread_create(&pid, NULL, func, NULL);
// wait cv1
pthread_cond_wait(&cv1, &mutex1);
pthread_mutex_lock(&mutex2);
pthread_mutex_unlock(&mutex1);
// signal cv2
pthread_cond_signal(&cv2);
pthread_mutex_unlock(&mutex2);
//cancel the thread
err = pthread_cancel(pid);
assert(err == 0);
puts("main: sleeping forever");
Sleep(INFINITE);
}
int main(int argc, char **argv) {
test();
return 0;
}
--
Romano Paolo Tenca
next reply other threads:[~2006-06-12 12:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-06-12 12:27 Romano Paolo Tenca [this message]
2006-06-13 10:25 ` Romano Paolo Tenca
2006-06-13 14:03 Bossom, John
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=448D5D96.4070902@telvia.it \
--to=rotenca@telvia.it \
--cc=pthreads-win32@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).