Process.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. /* This Hello World demostrate a simple multithread program */
  4. #define DO_BENCH 0
  5. #include "pal.h"
  6. #include "pal_debug.h"
  7. #include "api.h"
  8. int main (int argc, char ** argv)
  9. {
  10. int count = 0;
  11. #if DO_BENCH != 1
  12. pal_printf("In process: %s", argv[0]);
  13. for (int i = 1 ; i < argc ; i++)
  14. pal_printf(" %s", argv[i]);
  15. pal_printf("\n");
  16. #endif
  17. if (argc == 1) {
  18. unsigned long time = DkSystemTimeQuery ();
  19. char time_arg[24];
  20. snprintf(time_arg, 24, "%ld", time);
  21. const char * newargs[4] = { "Process", "0", time_arg, NULL };
  22. PAL_HANDLE proc = DkProcessCreate ("file:Process", 0, newargs);
  23. if (!proc)
  24. pal_printf("Can't create process\n");
  25. DkObjectClose(proc);
  26. DkThreadDelayExecution(30000000);
  27. } else {
  28. count = atoi (argv[1]);
  29. if (count < 100) {
  30. count++;
  31. char count_arg[8];
  32. snprintf(count_arg, 8, "%d", count);
  33. const char * newargs[4] = { "Process", count_arg, argv[2], NULL };
  34. PAL_HANDLE proc = DkProcessCreate ("file:Process", 0, newargs);
  35. if (!proc)
  36. pal_printf("Can't creste process\n");
  37. DkObjectClose(proc);
  38. } else {
  39. unsigned long end = DkSystemTimeQuery ();
  40. unsigned long start = atol (argv[2]);
  41. pal_printf ("wall time = %d\n", end - start);
  42. }
  43. }
  44. DkProcessExit(0);
  45. return 0;
  46. }