1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
from rpython.rlib import rgil
from rpython.translator.c.test.test_standalone import StandaloneTests
class BaseTestGIL(StandaloneTests):
def test_simple(self):
def main(argv):
rgil.release()
# don't have the GIL here
rgil.acquire()
rgil.yield_thread()
print "OK" # there is also a release/acquire pair here
return 0
main([])
t, cbuilder = self.compile(main)
data = cbuilder.cmdexec('')
assert data == "OK\n"
def test_after_thread_switch(self):
class Foo:
pass
foo = Foo()
foo.counter = 0
def seeme():
foo.counter += 1
def main(argv):
rgil.invoke_after_thread_switch(seeme)
print "Test" # one release/acquire pair here
print foo.counter
print foo.counter
return 0
t, cbuilder = self.compile(main)
data = cbuilder.cmdexec('')
assert data == "Test\n1\n2\n"
class TestGILAsmGcc(BaseTestGIL):
gc = 'minimark'
gcrootfinder = 'asmgcc'
class TestGILShadowStack(BaseTestGIL):
gc = 'minimark'
gcrootfinder = 'shadowstack'
|