Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <pthread.h>
- pthread_mutex_t mutex=PTHREAD_MUTEX_INITIALIZER;
- pthread_cond_t empty=PTHREAD_COND_INITIALIZER;
- pthread_cond_t full=PTHREAD_COND_INITIALIZER;
- typedef struct elem {
- int value;
- struct elem *next;
- } Elem;
- typedef struct blockingQueue {
- unsigned sizeBuffer, statusBuffer;
- Elem *head, *last;
- } BlockingQueue;
- BlockingQueue BQ;
- Elem queue;
- int P, C, N;
- unsigned B=10;
- void newBlockingQueue ()
- {
- BQ.sizeBuffer=B;
- BQ.statusBuffer=0;
- BQ.head=NULL;
- BQ.last=NULL;
- queue.value=0;
- queue.next=NULL;
- return;
- }
- void putBlockingQueue (int newValue)
- {
- Elem *novo;
- Elem *iter;
- novo=(Elem *)malloc(sizeof(Elem));
- novo->value=newValue;
- novo->next=NULL;
- if (BQ.statusBuffer==0) {
- queue.next=novo;
- BQ.head=novo;
- BQ.last=novo;
- BQ.statusBuffer++;
- }
- else {
- iter=queue.next;
- while (iter->next!=NULL) {
- iter=iter->next;
- }
- iter->next=novo;
- BQ.last=novo;
- BQ.statusBuffer++;
- }
- }
- void *producer (void *threadidp)
- {
- }
- void takeBlockingQueue ()
- {
- }
- void *consumer (void *threadidc)
- {
- }
- int main ()
- {
- freopen ("inQ4.in", "r", stdin);
- int i;
- Elem *iter;
- newBlockingQueue();
- for (i=0; i<10; i++) {
- putBlockingQueue(i);
- }
- iter=queue.next;
- for (iter; iter!=NULL; iter=iter->next) {
- printf ("%d ", iter->value);
- }
- printf ("OK\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement