V5
This commit is contained in:
parent
38443df097
commit
9e67f43b8e
3 changed files with 29 additions and 19 deletions
|
@ -1,13 +1,5 @@
|
|||
|
||||
void BoundedBuffer::push(string item){
|
||||
/* if(there is some empty slot){//data.size < b
|
||||
data.push_back(item);
|
||||
}else{
|
||||
wait();
|
||||
}
|
||||
*/ //replace with
|
||||
|
||||
|
||||
|
||||
empty.P();
|
||||
data.push_back(item);
|
||||
|
@ -16,6 +8,8 @@ void BoundedBuffer::push(string item){
|
|||
}
|
||||
|
||||
void BoundedBuffer::pop(){
|
||||
|
||||
full.P();
|
||||
data.pop(item);
|
||||
empty.V();
|
||||
}
|
||||
|
|
@ -6,13 +6,11 @@ using namespace std;
|
|||
unsigned int n = 20, b = 100, w = 5;
|
||||
|
||||
class BoundedBuffer{
|
||||
//int b;
|
||||
|
||||
Semaphore *full = new Semaphore(0); //initialized to 0, Since there are 0 full slots
|
||||
Semaphore *empty = new Semaphore(b); //initialized to b, Since all the slots are empty
|
||||
Semaphore *mutex = new Semaphore(1);
|
||||
|
||||
|
||||
|
||||
vector<string> data;
|
||||
|
||||
//BoundedBuffer(
|
||||
|
|
|
@ -78,6 +78,7 @@ int main(int argc, char * argv[]) {
|
|||
|
||||
cout << "TEST: " << n << b << w << endl;
|
||||
|
||||
BoundedBuffer buff();
|
||||
Semaphore sema(5);
|
||||
cout << "CLIENT STARTED:" << endl;
|
||||
|
||||
|
@ -85,11 +86,12 @@ int main(int argc, char * argv[]) {
|
|||
|
||||
if(pid == 0){
|
||||
cout << "Establishing control channel... " << flush;
|
||||
RequestChannel chan("control", RequestChannel::CLIENT_SIDE);
|
||||
control chan("control", RequestChannel::CLIENT_SIDE);
|
||||
cout << "done." << endl;
|
||||
|
||||
/* -- Start sending a sequence of requests */
|
||||
|
||||
/*
|
||||
string reply1 = chan.send_request("hello");
|
||||
cout << "Reply to request 'hello' is '" << reply1 << "'" << endl;
|
||||
|
||||
|
@ -111,6 +113,8 @@ int main(int argc, char * argv[]) {
|
|||
|
||||
string reply4 = chan.send_request("quit");
|
||||
cout << "Reply to request 'quit' is '" << reply4 << "'" << endl;
|
||||
*/
|
||||
|
||||
}else{
|
||||
execve("dataserver", argv, argv);
|
||||
}
|
||||
|
@ -118,10 +122,24 @@ int main(int argc, char * argv[]) {
|
|||
usleep(1000000);
|
||||
}
|
||||
|
||||
void Req_Thread(RequestChannel chan){
|
||||
//handles the data moving between the Client and Bounded Buffer
|
||||
for(int i=0; i < 3; i++){
|
||||
chan.send_request("newthread");
|
||||
}
|
||||
}
|
||||
|
||||
void Worker_Thread(void* arg){
|
||||
//handles the data moving between the Server and Bounded Buffer
|
||||
channel_name = control.send_request("newthread");
|
||||
RequestChannel * channel_ret = new RequestChannel(channel_name, CLIENT_SIDE);
|
||||
while(true){
|
||||
string req = BB.pull();
|
||||
string resp = channel_ret -> send_request(req);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
void* Worker_Thread();
|
||||
|
||||
void* Req_Thread();
|
||||
|
||||
void*
|
||||
*/
|
Reference in a new issue