lab3 program with threads
first to be worked out is eventbarrier primitive:
class EventBarrier {
public:
void wait();
void signal();
void complete();
int waiters();
private:
semaphore signal; //i think it's initial value must be zero for at the very beginning the event doesn't happen, and if thread use EventBarrier, it may use p() to check if the event happened for the val must be nonnegative or the thread has to wait for v();
List queue; // the list that stores the waiting threads.
int count; // the counter for the waiting threads, this is easy to understand it.
}
this is the model for the class's primitive.
the function wait() is easy to implement, if called, it must check the semaphore first, if the semaphore's val is still zero, the thread must wait and be inserted into the waiting queue. if want to return from this function, it's condtion is the semaphore's val won't be zero any more.
and the function signal(), i don't know how to implement it,yet.the key is how or who will call this function and let go all the threads?
function complete(), it may wait and check if the count is decrease to be zero.
and the function waiters(), i don't need to explain any more about it.
writing for this step, i get a idea about the function signal(), fking my fool thinking. the caller must be the event process, it must contain a variable of the eventBarrier. so the thing goes to be easy.
class EventBarrier {
public:
void wait();
void signal();
void complete();
int waiters();
private:
semaphore signal; //i think it's initial value must be zero for at the very beginning the event doesn't happen, and if thread use EventBarrier, it may use p() to check if the event happened for the val must be nonnegative or the thread has to wait for v();
List queue; // the list that stores the waiting threads.
int count; // the counter for the waiting threads, this is easy to understand it.
}
this is the model for the class's primitive.
the function wait() is easy to implement, if called, it must check the semaphore first, if the semaphore's val is still zero, the thread must wait and be inserted into the waiting queue. if want to return from this function, it's condtion is the semaphore's val won't be zero any more.
and the function signal(), i don't know how to implement it,yet.the key is how or who will call this function and let go all the threads?
function complete(), it may wait and check if the count is decrease to be zero.
and the function waiters(), i don't need to explain any more about it.
writing for this step, i get a idea about the function signal(), fking my fool thinking. the caller must be the event process, it must contain a variable of the eventBarrier. so the thing goes to be easy.
0 Comments:
Post a Comment
<< Home