Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define MAX 1000000000
- Elemento buffer[MAX];
- int nelem = 0;
- pthread_mutex_t m;
- pthread_cond_t c;
- void* Produtor(void* dta)
- {
- Elemento *e;
- while(1)
- {
- e = produzElemento(buffer);
- pthread_mutex_lock(&m);
- insereElemento(e);
- nelem++;
- pthread_cond_signal(&c);
- pthread_mutex_unlock(&m);
- }
- return NULL;
- }
- void* Consumidor(void* dta)
- {
- Elemento *e;
- while(1)
- {
- pthread_mutex_lock(&m);
- while (nelem == 0)
- {
- pthread_mutex_unlock(&m);
- pthread_cond_wait(&c);
- pthread_mutex_lock(&m);
- }
- e = retiraElemento(buffer);
- nelem--;
- pthread_mutex_unlock(&m);
- consomeElemento(e);
- }
- return NULL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement