Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <assert.h>
- #include <pthread.h>
- #include "job_queue.h"
- void* push(void* arg){
- struct job_queue q = *((struct job_queue*) arg);
- printf("push worker\n");
- int hej5 = 5;
- job_queue_push(&q, &hej5);
- return 0;
- }
- void* pop(void* arg){
- struct job_queue q = *((struct job_queue*) arg);
- printf("pop_worker\n");
- void** data;
- data = malloc(sizeof(void*) );
- job_queue_pop(&q, data);
- int* d = data[0];
- printf("data: %d\n", *d);
- return 0;
- }
- int main()
- {
- pthread_t tid1, tid2;
- struct job_queue q;
- job_queue_init(&q, 4);
- printf("%d \n", q.max_capacity);
- int hej = 1;
- job_queue_push(&q, &hej);
- /*int* ib = q.buffer[0];
- printf("%d", *ib);*/
- int hej2 = 2;
- job_queue_push(&q, &hej2);
- int hej3 = 3;
- job_queue_push(&q, &hej3);
- int hej4 = 4;
- job_queue_push(&q, &hej4);
- //printf("hej");
- printf("front %d \n", q.front);
- printf("rear %d \n", q.rear);
- printf("available %d \n", q.available);
- assert(pthread_create(&tid1, NULL, &push, &q) == 0);
- assert(pthread_create(&tid2, NULL, &pop, &q) == 0);
- pthread_join(tid1, NULL);
- pthread_join(tid2, NULL);
- int* ib = q.buffer[0];
- printf("Efter pop og push %d \n", *ib);
- //job_queue_pop(&q, data);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement