public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
From: "Kevin D. Clark" <kclark@cabletron.com>
To: Pthreads Developers List <pthreads-win32@sourceware.cygnus.com>
Subject: Re: C++ cleanup handler execution
Date: Fri, 14 Jan 2000 08:27:00 -0000	[thread overview]
Message-ID: <14463.20160.891089.94040@cabletron.com> (raw)
In-Reply-To: <14463.19695.396800.542343@cabletron.com>

Sorry, in my previous email my test file got garbled.  
My fault.

--kevin

Here's the test file:


// this is a C++ program

#ifdef __unix
#include <unistd.h>
#else

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

void *canceledRoutine(void *), *anotherRoutine(void *);

pthread_t canceledThread, anotherThread;

int
main(int argc, char *argv[])
{
  int i = 0;
  pthread_attr_t tattr;
  pthread_attr_init(&tattr);
  pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);

  for (i=0; i<10000; i++) {
    pthread_create(&canceledThread, &tattr, canceledRoutine, (void *)i);
    pthread_create(&anotherThread, 0, anotherRoutine, (void *)i);

    pthread_join(anotherThread, 0);
  }

  sleep(5);
}

void cancelCleanup(void *arg)
{
  int i = (int)arg;

  fprintf(stderr, "%d -- Hey, I've been canceled!\n", i);
}


void *
canceledRoutine(void *arg)
{
  int i = (int)arg;

  pthread_cleanup_push(cancelCleanup, i);

  while(1) {
    // sleep() is defined to be a cancelation point
    sleep(1);
  }
  
  pthread_cleanup_pop(0);
  
  return 0;
}

void *
anotherRoutine(void *arg)
{
  int i = (int)arg;

  pthread_cancel(canceledThread);
  
  return 0;
}

  reply	other threads:[~2000-01-14  8:27 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <000601bf578e$3c89a750$208e08d0@fflaptop>
2000-01-05 17:35 ` Ross Johnson
2000-01-06 14:11   ` Kevin D. Clark
2000-01-06 18:17     ` Ross Johnson
2000-01-14  8:19       ` Kevin D. Clark
2000-01-14  8:27         ` Kevin D. Clark [this message]
2000-01-14  8:30           ` Kevin D. Clark
2000-01-14  8:36           ` Kevin D. Clark
2000-02-02 10:08             ` pthread_cancel() problems Kevin D. Clark
2000-06-14 18:06         ` Question about condition variable Taci Ãœlker
     [not found]           ` <3949054F.3127@surfnshop.com>
2000-06-16  7:33             ` Taci Ãœlker

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=14463.20160.891089.94040@cabletron.com \
    --to=kclark@cabletron.com \
    --cc=pthreads-win32@sourceware.cygnus.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).