Broadcast.c 1.1 KB

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