<s> from pypy . module . thread . test . support import GenericTestThread <EOL> from pypy . translator . c . test . test_genc import compile <EOL> class AppTestLock ( GenericTestThread ) : <EOL> def test_lock ( self ) : <EOL> import thread <EOL> lock = thread . allocate_lock ( ) <EOL> assert type ( lock ) is thread . LockType <EOL> assert lock . locked ( ) is False <EOL> raises ( thread . error , lock . release ) <EOL> assert lock . locked ( ) is False <EOL> lock . acquire ( ) <EOL> assert lock . locked ( ) is True <EOL> lock . release ( ) <EOL> assert lock . locked ( ) is False <EOL> raises ( thread . error , lock . release ) <EOL> assert lock . locked ( ) is False <EOL> feedback = [ ] <EOL> lock . acquire ( ) <EOL> def f ( ) : <EOL> self . busywait ( <NUM_LIT> ) <EOL> feedback . append ( <NUM_LIT> ) <EOL> lock . release ( ) <EOL> assert lock . locked ( ) is True <EOL> thread . start_new_thread ( f , ( ) ) <EOL> lock . acquire ( ) <EOL> assert lock . locked ( ) is True <EOL> assert feedback == [ <NUM_LIT> ] <EOL> def test_lock_in_with ( self ) : <EOL> import thread <EOL> lock = thread . allocate_lock ( ) <EOL> feedback = [ ] <EOL> lock . acquire ( ) <EOL> def f ( ) : <EOL> self . busywait ( <NUM_LIT> ) <EOL> feedback . append ( <NUM_LIT> ) <EOL> lock . release ( ) <EOL> assert lock . locked ( ) is True <EOL> thread . start_new_thread ( f , ( ) ) <EOL> exec """<STR_LIT>""" in { "<STR_LIT>" : lock , "<STR_LIT>" : feedback } <EOL> assert lock . locked ( ) is False <EOL> def test_compile_lock ( ) : <EOL> from pypy . rlib import rgc <EOL> from pypy . module . thread . ll_thread import allocate_lock <EOL> def g ( ) : <EOL> l = allocate_lock ( ) <EOL> ok1 = l . acquire ( True ) <EOL> ok2 = l . acquire ( False ) <EOL> l . release ( ) <EOL> ok3 = l . acquire ( False ) <EOL> res = ok1 and not ok2 and ok3 <EOL> return res <EOL> g . _dont_inline_ = True <EOL> def f ( ) : <EOL> res = g ( ) <EOL> return res <EOL> fn = compile ( f , [ ] , gcpolicy = '<STR_LIT>' ) <EOL> res = fn ( ) <EOL> assert res <EOL> class AppTestLockAgain ( GenericTestThread ) : <EOL> test_lock_again = AppTestLock . test_lock . im_func </s>
