Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <assert.h>
  4. #include <pthread.h>
  5.  
  6. #include "job_queue.h"
  7.  
  8. void* push(void* arg){
  9. struct job_queue q = *((struct job_queue*) arg);
  10. printf("push worker\n");
  11. int hej5 = 5;
  12. job_queue_push(&q, &hej5);
  13. return 0;
  14. }
  15.  
  16. void* pop(void* arg){
  17.  
  18. struct job_queue q = *((struct job_queue*) arg);
  19. printf("pop_worker\n");
  20. void** data;
  21. data = malloc(sizeof(void*) );
  22. job_queue_pop(&q, data);
  23. int* d = data[0];
  24. printf("data: %d\n", *d);
  25. return 0;
  26. }
  27. int main()
  28. {
  29. pthread_t tid1, tid2;
  30.  
  31. struct job_queue q;
  32. job_queue_init(&q, 4);
  33.  
  34. printf("%d \n", q.max_capacity);
  35. int hej = 1;
  36. job_queue_push(&q, &hej);
  37. /*int* ib = q.buffer[0];
  38. printf("%d", *ib);*/
  39. int hej2 = 2;
  40. job_queue_push(&q, &hej2);
  41. int hej3 = 3;
  42. job_queue_push(&q, &hej3);
  43. int hej4 = 4;
  44. job_queue_push(&q, &hej4);
  45. //printf("hej");
  46.  
  47. printf("front %d \n", q.front);
  48. printf("rear %d \n", q.rear);
  49. printf("available %d \n", q.available);
  50.  
  51.  
  52. assert(pthread_create(&tid1, NULL, &push, &q) == 0);
  53. assert(pthread_create(&tid2, NULL, &pop, &q) == 0);
  54. pthread_join(tid1, NULL);
  55. pthread_join(tid2, NULL);
  56. int* ib = q.buffer[0];
  57. printf("Efter pop og push %d \n", *ib);
  58.  
  59. //job_queue_pop(&q, data);
  60.  
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement