Advertisement
Guest User

Untitled

a guest
Sep 21st, 2014
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. int main() {
  2. int status, i;
  3. pthread_t tr[NO_RECIEVERS], tw[NO_SENDERS], bd;
  4. i=1;
  5.  
  6. for(i=1; i<=NO_SENDERS; i++) {
  7. pthread_create(&tw[i-1], NULL, writer, &i);
  8. }
  9.  
  10. for(i=1; i<=NO_RECIEVERS; i++) {
  11. printf("%dn", i);
  12. pthread_create(&tr[i-1], NULL, reader, &i);
  13. }
  14.  
  15. pthread_create(&bd, NULL ,daemon_thread, NULL);
  16.  
  17. for(i=1; i<=NO_SENDERS; i++) {
  18. pthread_join(tw[i-1], NULL);
  19. }
  20.  
  21. for(i=1; i<=NO_RECIEVERS; i++) {
  22. pthread_join(tr[i-1], NULL);
  23. }
  24. pthread_join(bd, NULL);
  25.  
  26. return 0;
  27. }
  28.  
  29. void* reader(void *val) {
  30. int ret, fd, id;
  31. struct mssg data;
  32. id = *(int*)val;
  33. printf("id: %d %dn", id, *(int*)val);
  34. while(1) {
  35.  
  36. ...
  37. id: 1 1
  38. ...
  39. id: 2 2
  40. ...
  41. id: 1 1
  42.  
  43. ...
  44. id: 1 1
  45. ...
  46. 2
  47. id: 2 2
  48. ...
  49. id: 4 4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement