how to make a function thread-safe ?
Harry George
hgg9140 at cola.ca.boeing.com
Fri Mar 9 17:21:41 EST 2001
A true function with no global side-effects should be thread-safe.
[Or at least that's true in any language I've multi-threaded so far.]
If there are global side effects, you need to capture them in some
structure (with a class being a convenient format), and pass that (one
per thread) to the function.
Your suggestion is one of several syntactic alternative to passing a
structure: make the function a method of the class which has the
per-thread data.
j vickroy <jim.vickroy at noaa.gov> writes:
> If a function may be applied (simultaneously) by multiple threads is the
> safe (correct) procedure to wrap the function inside a class and have
> each thread create its own instance of the class?
>
> Thanks
--
Harry George E-mail: harry.g.george at boeing.com
The Boeing Company Renton: (425) 237-6915
P. O. Box 3707 02-CA Everett: (425) 266-3868
Seattle, WA 98124-2207 Page: (425) 631-8803
More information about the Python-list
mailing list