00001 # This file is Copyright 2003, 2006, 2007, 2009 Dean Hall. 00002 # 00003 # This file is part of the Python-on-a-Chip program. 00004 # Python-on-a-Chip is free software: you can redistribute it and/or modify 00005 # it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1. 00006 # 00007 # Python-on-a-Chip is distributed in the hope that it will be useful, 00008 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00009 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00010 # A copy of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1 00011 # is seen in the file COPYING up one directory from this. 00012 00013 # 00014 # System Test 096 00015 # Create library function to spawn a new thread 00016 # 00017 00018 import sys 00019 00020 sharedVar = 42 00021 00022 00023 def f1(): 00024 global sharedVar 00025 print "f1: sharedVar is ", sharedVar 00026 while sharedVar == 42: 00027 pass 00028 print "f1: sharedVar is ", sharedVar 00029 00030 00031 def f2(): 00032 global sharedVar 00033 print "f2: killing time..." 00034 for i in range(32): 00035 print i, 00036 print 00037 print "f2: setting sharedVar to 99" 00038 sharedVar = 99 00039 00040 sys.runInThread(f2) 00041 sys.runInThread(f1)