[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] Terminering af tråde



Peter Makholm wrote:
Peter Maersk-Moller <sslug@sslug> writes:
Så hvordan sender man et signal til en specifik tråd på en nogenlunde
portabel måde ?
pad?

http://opengroup.org/onlinepubs/007908775/xsh/pthread_kill.html

Nedenstaaende compileret med "cc file.c -o file -lpthread" fører desværre ikke til at read() returnerer ....

Output er

# ./test
Read thread
Sending Signal
Alarm clock
#

========================================================================
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <pthread.h>

void mythread() {
  char buf;
  int n = 0;
  fprintf(stderr, "Read thread\n");
  while (n=read(0,&buf,1)) {
    fprintf(stderr,"Read %d\n", n);
  }
  fprintf(stderr, "Read terminated %d\n",n);
}

main(int argc, char** argv) {
  pthread_t thread;
  pthread_create(&thread, NULL,(void*) &mythread, NULL);
  system("sleep 2");
  fprintf(stderr, "Sending Signal\n");
  pthread_kill(thread, SIGALRM);
  system("sleep 2");
  fprintf(stderr, "exit\n");
}



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2008-04-01, 02:01 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *