Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,48 @@
|
|||
monitor Queue {
|
||||
var items = []
|
||||
public function put (item) {
|
||||
items.append (item)
|
||||
notify()
|
||||
}
|
||||
|
||||
public function get() {
|
||||
while (items.size() == 0) {
|
||||
wait()
|
||||
}
|
||||
var item = items[0]
|
||||
items <<= 1
|
||||
return item
|
||||
}
|
||||
|
||||
public function close {
|
||||
items.append (none)
|
||||
}
|
||||
}
|
||||
|
||||
thread reader (queue) {
|
||||
var numlines = 0
|
||||
for (;;) {
|
||||
var line = queue.get()
|
||||
if (typeof(line) == "none") {
|
||||
break
|
||||
}
|
||||
print (line)
|
||||
numlines++
|
||||
}
|
||||
println ("Number of lines: " + numlines)
|
||||
}
|
||||
|
||||
thread writer (queue, lines) {
|
||||
foreach line lines {
|
||||
queue.put (line)
|
||||
}
|
||||
queue.close()
|
||||
}
|
||||
|
||||
var queue = new Queue()
|
||||
var lines = readfile ("input.txt")
|
||||
var r = reader(queue)
|
||||
var w = writer(queue, lines)
|
||||
|
||||
join (r)
|
||||
join (w)
|
||||
Loading…
Add table
Add a link
Reference in a new issue