2021-02-09 17:13:45 +03:00
|
|
|
####
|
|
|
|
# Demonstration of how container access is currently broken
|
|
|
|
# by threads and needs reader/writer locks.
|
|
|
|
####
|
|
|
|
import os
|
|
|
|
if 'KUROKO_TEST_ENV' in os.environ:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
from fileio import open, stdin
|
|
|
|
from threading import Thread
|
|
|
|
|
|
|
|
let l = []
|
2021-02-10 12:19:10 +03:00
|
|
|
let d = {}
|
2021-02-09 17:13:45 +03:00
|
|
|
let stop = False
|
|
|
|
|
|
|
|
class Racer(Thread):
|
|
|
|
def run(self):
|
|
|
|
let myRando = open('/dev/urandom','rb')
|
|
|
|
while not stop:
|
2021-02-10 04:20:56 +03:00
|
|
|
let bytes = myRando.read(4)
|
|
|
|
let choice = (bytes[0] << 24) | (bytes[1] << 16) | (bytes[2] << 8) | (bytes[3])
|
|
|
|
if choice > 2147483647:
|
2021-02-09 17:13:45 +03:00
|
|
|
l.append('test')
|
|
|
|
else if l:
|
|
|
|
l[choice % len(l)] += choice
|
2021-02-10 12:19:10 +03:00
|
|
|
d[choice] = str(choice)
|
2021-02-09 17:13:45 +03:00
|
|
|
|
2021-02-10 04:20:56 +03:00
|
|
|
let racers = [Racer() for i in range(5)]
|
2021-02-09 17:13:45 +03:00
|
|
|
|
2021-02-10 04:20:56 +03:00
|
|
|
for racer in racers:
|
|
|
|
racer.start()
|
2021-02-09 17:13:45 +03:00
|
|
|
|
|
|
|
print("Press enter to stop.")
|
|
|
|
stdin.readline()
|
|
|
|
|
|
|
|
stop = True
|
|
|
|
|
|
|
|
print("Waiting for threads...")
|
2021-02-10 04:20:56 +03:00
|
|
|
for racer in racers:
|
|
|
|
racer.join()
|
2021-02-09 17:13:45 +03:00
|
|
|
print("Here's l:")
|
|
|
|
print(l)
|
2021-02-10 12:19:10 +03:00
|
|
|
print("Here's d:")
|
|
|
|
print(d)
|