Broadcast.c 1.1 KB

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