From 4f3b3d71000e5c8240647a2c10c081259a68b4c1 Mon Sep 17 00:00:00 2001 From: Jeff Connelly Date: Sun, 25 May 2008 14:36:56 -0700 Subject: [PATCH] Instruction-level CPU simulator: fix SyntaxWarning on globals. The 'global' command needs only to be used in the beginning of a function, to indicate that the variable refers to a global; it doesn't need to be used at the global scope. --- asm/logicCpu.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/asm/logicCpu.py b/asm/logicCpu.py index 58bb47e..de4aeef 100755 --- a/asm/logicCpu.py +++ b/asm/logicCpu.py @@ -15,11 +15,9 @@ import sys, os, threading, time, signal # for safe termination CONTINUE = 0 TERMINATE = 1 -global cont_exec cont_exec = CONTINUE # for concurency -global locked locked = False TRACE = False @@ -47,6 +45,8 @@ registers = { # Thread that gets input from user class CPUInput (threading.Thread): def run (self): + global cont_exec + while True: print "Register Status: %s :" % registers, @@ -54,13 +54,11 @@ class CPUInput (threading.Thread): user_input = raw_input('Input value for IN:') except EOFError, e: get_lock() - global cont_exec cont_exec = TERMINATE release_lock() sys.exit() get_lock() - global cont_exec if cont_exec == TERMINATE: sys.exit() release_lock() @@ -80,8 +78,8 @@ def get_lock(): ''' Busy wait lock to avoid race conditions. This function retrieves the lock. ''' - global locked + while locked: a = 1 locked = True @@ -90,6 +88,7 @@ def release_lock(): ''' This function releases the lock. ''' global locked + locked = False -- 2.11.4.GIT