home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / csim / source.lha / source / Threads / GnuThreads / bm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-14  |  785 b   |  45 lines

  1. #include <stdio.h>
  2. #include <malloc.h>
  3. #include <sys/time.h>
  4. #include <sys/timeb.h>
  5. #include "gnulwp.h"
  6. struct sem *s;
  7.  
  8. void f (int n, char** dummy2 = 0, void* dummy3 = 0)
  9. {
  10.     while (n--)
  11.         yieldp ();
  12.     signals (s);
  13.     suicidep ();
  14. }
  15.  
  16. void g (Thread_Par)
  17. {
  18.     suicidep ();
  19. }
  20.  
  21. main ()
  22. {
  23.     int n, t;
  24.     struct timeb ts, te;
  25.  
  26.     initlp (1);
  27.     s = creats (0);
  28.     creatp (1, f, 4096, 5000, 0, 0);
  29.     creatp (1, f, 4096, 5000, 0, 0);
  30.     ftime (&ts);
  31.     waits (s);
  32.     waits (s);
  33.     ftime (&te);
  34.     t = (int) (1000*(te.time-ts.time) + te.millitm - ts.millitm);
  35.     free (s);
  36.     printf ("Context switching: %d ms /10000\n", t);
  37.  
  38.     ftime (&ts);
  39.     for (n=10000; n--; )
  40.         creatp (2, g, 4096, 0, 0, 0);
  41.     ftime (&te);
  42.     t = (int) (1000*(te.time-ts.time) + te.millitm - ts.millitm);
  43.     printf ("Process creation: %d ms /10000\n", t);
  44. }
  45.