<br><br><div class="gmail_quote">On Fri, Dec 16, 2011 at 8:33 AM, Tim Wintle <span dir="ltr"><<a href="mailto:tim.wintle@teamrubber.com">tim.wintle@teamrubber.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Fri, 2011-12-16 at 05:21 -0800, Brad Tilley wrote:<br>
> 107 void increment_counter( unsigned int& counter )<br>
> 108 {<br>
> 109 boost::mutex::scoped_lock lock( counter_lock );<br>
> 110 ++counter;<br>
> 111 }<br>
<br>
<br>
with counter_lock:<br>
counter += 1<br>
<br>
<br>
... where counter_lock is a threading.Lock instance.<br>
<br>
(see docs for the threading module)</blockquote><div><br> </div><div><br>So something like this then:<br><br>import threading<br><br>shared_container = []<br>lock = threading.Lock()<br><br>class thread_example( threading.Thread ):<br>
<br> def __init__( self ):<br> threading.Thread.__init__ (self)<br><br> def run(t):<br> lock<br> shared_container.append(<a href="http://t.name">t.name</a>)<br><br># main<br><br>threads = []<br>
for i in xrange(10):<br> thread = thread_example()<br> threads.append(thread)<br> <br>for thread in threads:<br> thread.start()<br><br>for item in shared_container:<br> print item <br></div></div><br>