Broadcast.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 1
  5. #include "pal.h"
  6. #include "pal_debug.h"
  7. int main (int argc, char ** argv)
  8. {
  9. if (argc == 1) {
  10. char id[2] = { '0', 0 };
  11. const char * newargs[] = { "Broadcast", id, NULL };
  12. PAL_HANDLE proc[4];
  13. int i;
  14. for (i = 0 ; i < 4 ; i++) {
  15. id[0] = '0' + i + 1;
  16. proc[i] = DkProcessCreate ("file:Broadcast", 0, newargs);
  17. }
  18. DkThreadDelayExecution(1000000);
  19. DkStreamWrite(pal_control.broadcast_stream, 0, 12, "Hello World", NULL);
  20. for (i = 0 ; i < 4 ; i++) {
  21. char byte;
  22. DkStreamRead(proc[i], 0, 1, &byte, NULL, 0);
  23. pal_printf("process %d exited\n", i + 1);
  24. }
  25. } else {
  26. char bytes[12];
  27. pal_printf("process %s started\n", argv[1]);
  28. DkStreamRead(pal_control.broadcast_stream, 0, 12, bytes, NULL, 0);
  29. pal_printf("process %s received: %s\n", argv[1], bytes);
  30. DkStreamWrite(pal_control.parent_process, 0, 1, "0", NULL);
  31. }
  32. return 0;
  33. }