Jump to content

J (programming language)

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 4.47.181.32 (talk) at 05:37, 19 August 2002. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
  1. include <pthread.h>
  2. include <stdio.h>

char * buf = "abcdefghijklmnopqrstuvwxyz"; int num_pthreads = 2; int count = 60; int fd = 1;

void * new_thread(void * arg) {

   int i;
   for (i = 0; i < count; i++) {

write(fd, arg, 1); sleep(1);

   }
   return(NULL);

}

main() {

  pthread_t thread;
  int i;
  for (i = 0; i < num_pthreads; i++) {

if (pthread_create(&thread, NULL, new_thread, (void *)(buf + i))) { fprintf(stderr, "error creating a new thread \n"); exit(1); } pthread_detach(thread);

  }
  pthread_exit(NULL);

}