Newbie Threads question
mbf2y at my-dejanews.com
mbf2y at my-dejanews.com
Sat May 1 13:32:38 EDT 1999
Hello everyone-
I have never done any threads programming whatsoever. I did take an Operating
Systems class back in College ('94) so I understand semaphores used to protect
resources, but haven't ever implemented them.
What I'd like to do is learn how to use threads by "parallelizing" a simple
set of now currently serialized tasks. No shared resources here. I
understand that in all likelihood I will not get any performance increase
(since I'm on a uni-processor system) but I want to learn how to do this
stuff.
hypothetically my code looks like this:
def func1(param):
result = []
# do a bunch of work, takes about 3 seconds of wall-clock time
return result
def func2(param):
result = []
# do a bunch of work, takes about 5 seconds of wall-clock time
return result
def func3(list1, list2):
result = []
# does work on the two lists passed in, takes 0.5 secs of wall-clock time
return result
#my main loop simplified
list1 = func1(x)
list2 = func2(y)
reallist = func3(list1,list2)
#do something with reallist.
Since func1 and func2 are completely independent - IE do not use any of the
same resources, to me this would be a great place to do the work in parallel.
What I want to do is something like this:
#my new main loop
list1 = thread.start_new_thread(func1,(x))
list2 = thread.start_new_thread(func2,(y))
reallist = func3(list1,list2)
I have read the documentation a couple of times, but what I don't know:
A) Is the return value of start_new_thread the same as the return value of the
function it calls?
B) Do I need to do anything fancy to make the func3 call wait until the calls
to func1 and func2 have both returned? For example, should I have the func1
and func2 calls aquire a lock at the start of the function and release it at
the end, and then make the main loop try to acquire both locks before
proceeding to the reallist = func3() call? If I did this, could the main
loop acquire the locks before the new threads do, causing deadlock?
C) I'm assuming I have to recompile python (since I didn't compile it "with
threads")
Thanks for any help...
-Fred
----
Michael "Fred" Fredericks
Graduate Student, University of Maryland Dept of Computer Science
fred-at-cs-dot-umd-dot-edu
I never read my deja news e-mail
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
More information about the Python-list
mailing list