public inbox for
 help / color / mirror / Atom feed
From: Rian Hunter <>
Subject: pthread_cancel and pthread_mutex_lock
Date: Wed, 11 Feb 2004 00:08:00 -0000	[thread overview]
Message-ID: <> (raw)


From reading the mailing list archives i found out that at one point in 
the pthreads-win32 library pthread_mutex_lock acted as a cancellation
point, but since then that was removed. I have a thread that needs to be
cancelled during a pthread_mutex_lock, so naturally i would have to set
the cancel type to PTHREAD_CANCEL_ASYNCHRONOUS as per the new behavior.
I'm not sure if pthread_mutex_lock can be asynchronously cancelled, but
i'm having a problem with code similar to this:

#include <pthread.h>
#include <stdio.h>

pthread_mutex_t inputLock;

void *t2(void *threadid) {
	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
	printf("created \n");

	/* waits to be cancelled here */
	/* never gets here */
	return 0;

int main() {
	pthread_t sender;
	int i;

	/* initialize and lock mutex */
	pthread_mutex_init(&inputLock, NULL);

	pthread_create(&sender, NULL, t2, NULL);

	/* psuedo sleep function */
	for(i = 0;i <10000000; i++) {}

	printf("slept and thread created\n");

	/* cancel thread and wait for termination */
	pthread_join(sender, NULL);

	/* check if thread was cancelled */
	printf("successfully canceled thread\n");

	/* test lock for continued operation */

	/* signify correct execution */
	printf("all done\n");
	return 0;


On FreeBSD the code executes correctly, at least i assume it is the
correct behavior of a pthreads implementation. On windows it just
freezes after it prints "created". I appreciate any help! thank you!

             reply	other threads:[~2004-02-11  0:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-11  0:08 Rian Hunter [this message]
2004-02-16 23:10 Simon Gerblich

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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \

* 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).