<br><br><div class="gmail_quote">On Fri, Dec 16, 2011 at 9:24 AM, Brad Tilley <span dir="ltr"><<a href="mailto:kj4eit@gmail.com">kj4eit@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br><br><div class="gmail_quote"><div><div></div><div class="h5">On Fri, Dec 16, 2011 at 8:33 AM, Tim Wintle <span dir="ltr"><<a href="mailto:tim.wintle@teamrubber.com" target="_blank">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></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" target="_blank">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></blockquote>
<div><br>Or perhaps run should look like this instead:<br><br>    def run(t):<br>        lock.acquire()<br>        shared_container.append(<a href="http://t.name">t.name</a>)<br>        lock.release() <br><br>That seems a bit barbaric to me, not sure.<br>
</div></div><br>