Skip to content

Commit

Permalink
wip trying to fix output
Browse files Browse the repository at this point in the history
  • Loading branch information
bergmanG committed Oct 10, 2021
1 parent b8665c5 commit ba08073
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
5 changes: 3 additions & 2 deletions TP3/coordinator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ int listener();
class remoteMutex
{
private:
queue<tuple<int, int>> mutexQ;
mutex mtx;
queue<tuple<int, int>> mutexQ;
bool acquired = false;
map<int, int> granted_map;
void grantNext()
Expand Down Expand Up @@ -57,8 +57,8 @@ class remoteMutex
}
void release()
{
cout << "RELEASED" << endl;
mtx.lock();
cout << "RELEASED" << endl;
if (mutexQ.empty())
{
acquired = false;
Expand Down Expand Up @@ -182,6 +182,7 @@ int listener()
}
else if (msg == RELEASE)
{
cout << process << " ";
rmutex.release();
}
else
Expand Down
6 changes: 6 additions & 0 deletions TP3/test_0.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

./cliente 2 10 172.26.86.132 &
./cliente 2 10 172.26.86.132 &

wait
9 changes: 9 additions & 0 deletions TP3/test_1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash


for i in 4 8 16 32; do
for j in $(seq $i); do
./cliente 2 10 172.26.86.132 &
done
wait
done
10 changes: 7 additions & 3 deletions lib/MyLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <math.h>
#include "MyLib.h"
#include <string>
#include <string.h>

using namespace std;

Expand All @@ -25,6 +24,11 @@ char *encode(int msg, int id)
}
void decode(char *buffer, int *message, int *id)
{
*message = stoi(strtok(buffer, "|"));
*id = stoi(strtok(NULL, "|"));
string delimiter = "|";
string s(buffer);
size_t pipe1 = s.find(delimiter);
*message = stoi(s.substr(0, pipe1));
s.erase(0, pipe1 + 1);
size_t pipe2 = s.find(delimiter);
*id = stoi(s.substr(0, pipe2));
}

0 comments on commit ba08073

Please sign in to comment.