I'm new to threading. I'm using 4 threads to run my function on 4 different things. Now I need to set a flag in my function which will do different calculations on each. What's the best way to do it? I'm trying to do this, is this correct. If there is any better way please suggest.
def func(i,flag):
while True:
if flag==0:
something
else:
something else
flag-=1
flag=["0","0","0","0"]
try:
thread.start_new_thread( func, (10,flag[0], ) )
thread.start_new_thread( func, (11,flag[1], ) )
thread.start_new_thread( func, (12,flag[2], ) )
thread.start_new_thread( func, (13,flag[3], ) )
except:
print "Error: unable to start thread"
#after sometime
flag[0]+=1
flag[2]+=1