40 lines
926 B
C++
40 lines
926 B
C++
#include <semaphore.h> // POSIX semaphores!
|
|
#include "list.hpp" // list implementation
|
|
#include "globals.hpp" // lists, sems, muts
|
|
#include "consumer.hpp"
|
|
|
|
int consume(block* c);
|
|
|
|
void *consumer (void *) {
|
|
block *c;
|
|
while (true) {
|
|
// wait for element on list2
|
|
wait(sem_list2);
|
|
// mutual exclusion for list2
|
|
wait(mut_list2);
|
|
//* c:=unlink(list-2);
|
|
c = unlink(list2);
|
|
// mutual exclusion for list2
|
|
signal(mut_list2);
|
|
|
|
//* consume_information_in_block(c)
|
|
consume(c);
|
|
|
|
// mutual exclusion for freelist
|
|
wait(mut_freelist);
|
|
//* link(c, freelist)
|
|
link(c, freelist);
|
|
// mutual exclusion for freelist
|
|
signal(mut_freelist);
|
|
// signal thread-1 to continue
|
|
signal(sem_freelist_minus_1);
|
|
// signal new element on freelist
|
|
signal(sem_freelist);
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
int consume(block *c) {
|
|
return 0;
|
|
}
|