• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
sleep() stops working when enabling pthread_cancel()
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

sleep() stops working when enabling pthread_cancel()


  • Subject: sleep() stops working when enabling pthread_cancel()
  • From: "Simon Strandgaard" <email@hidden>
  • Date: Fri, 12 Jan 2007 10:35:17 +0100

Any ideas why the program hangs second time sleep() is called?

--
Simon Strandgaard
http://opcoders.com/



prompt> uname -v
Darwin Kernel Version 8.8.1: Mon Sep 25 19:42:00 PDT 2006;
 root:xnu-792.13.8.obj~1/RELEASE_I386

prompt> g++ -D_APPLE_C_SOURCE proof.cpp

prompt> ./a.out
1
2
hello
hello
hello
3
4
^C

prompt> cat proof.cpp
#include <iostream>
using namespace std;

void* thread_main(void* arg) {
       pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0);
       pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0);

       while(1) {
               cout << "hello" << endl;
               sleep(1);
       }

       pthread_exit(0);
       return 0;
}

int main(int argc, char* argv[]) {
       pthread_t thread;

       cout << "1" << endl;
       pthread_create(&thread, 0, thread_main, 0);

       cout << "2" << endl;
       sleep(3);

       cout << "3" << endl;
       pthread_cancel(thread);

       cout << "4" << endl;
       sleep(3);

       cout << "5" << endl;
       return 0;
}
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: sleep() stops working when enabling pthread_cancel()
      • From: "Sean McBride" <email@hidden>
  • Prev by Date: Re: NOT solved: using long double math functions like sinl() with Cocoa
  • Next by Date: Re: int and short int on intel
  • Previous by thread: Re: Parsing Mail's .emlx message format
  • Next by thread: Re: sleep() stops working when enabling pthread_cancel()
  • Index(es):
    • Date
    • Thread