On Fri, Dec 16, 2011 at 8:33 AM, Tim Wintle <[email protected]>wrote:
> On Fri, 2011-12-16 at 05:21 -0800, Brad Tilley wrote:
> > 107 void increment_counter( unsigned int& counter )
> > 108 {
> > 109 boost::mutex::scoped_lock lock( counter_lock );
> > 110 ++counter;
> > 111 }
>
>
> with counter_lock:
> counter += 1
>
>
> ... where counter_lock is a threading.Lock instance.
>
> (see docs for the threading module)
So something like this then:
import threading
shared_container = []
lock = threading.Lock()
class thread_example( threading.Thread ):
def __init__( self ):
threading.Thread.__init__ (self)
def run(t):
lock
shared_container.append(t.name)
# main
threads = []
for i in xrange(10):
thread = thread_example()
threads.append(thread)
for thread in threads:
thread.start()
for item in shared_container:
print item
--
http://mail.python.org/mailman/listinfo/python-list