os-70-350

os-70-350 Commit Details


Date:2014-01-02 21:59:05 (11 years 8 months ago)
Author:Natalie Adams
Branch:master
Commit:055dd047a33cc84834c2963068af1d741902b764
Parents: 845c3fc444480bc20a4084661152541c483f6689
Message:Fixing monitor - console I/O is not thread safe

Changes:

File differences

ptypes-monitor/monitor.cpp
11
22
33
4
45
56
67
78
89
10
11
912
1013
1114
......
3538
3639
3740
41
3842
3943
4044
......
4448
4549
4650
51
52
4753
48
49
54
5055
5156
5257
......
8792
8893
8994
95
96
97
98
99
90100
#include <ptypes/ptypes.h>
#include <ptypes/pasync.h>
#include <ptypes/pstreams.h>
#include <vector>
USING_PTYPES
#define MAX 10
std::vector<string> output_s;
// Inspired on http://pages.cs.wisc.edu/~remzi/OSTEP/threads-monitors.pdf
class BoundedBuffer
{
if (fullEntries == 0)
full->wait();
int tmp = buffer[use];
buffer[use] = -1;
output("Consume " + itostring(tmp));
use = (use + 1) % MAX;
fullEntries--;
void output(string s)
{
// Performing console I/O from a thread causes strange behavior
// Even with a mutex lock
scopelock l(m_lock);
pout.put(s);
pout.puteol();
output_s.push_back(s);
}
};
t1.waitfor();
t2.waitfor();
for(size_t i = 0; i < output_s.size(); i++)
{
pout.put(output_s[i]);
pout.put("\n");
}
}

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.30451s using 14 queries.