Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.015 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.01; 'brad': 0.07; 'x-mailer:evolution 2.28.3': 0.07; 'instance.': 0.09; 'module)': 0.09; 'unsigned': 0.09; 'void': 0.15; '107': 0.16; 'subject:function': 0.16; 'threading': 0.16; 'cc:addr:python- list': 0.16; 'wrote:': 0.18; 'cc:no real name:2**0': 0.20; 'header :In-Reply-To:1': 0.22; 'cc:2**0': 0.24; '(see': 0.28; 'skip:b 20': 0.29; 'cc:addr:python.org': 0.29; 'fri,': 0.34; 'header:Reply- To:1': 0.71; 'reply-to:no real name:2**0': 0.72; 'received:bethere.co.uk': 0.84; '111': 0.91; 'subject:Make': 0.96 Subject: Re: Make a small function thread safe From: Tim Wintle To: Brad Tilley In-Reply-To: <10d3d04f-1708-4942-8e69-92b715f01ff8@p20g2000vbm.googlegroups.com> References: <10d3d04f-1708-4942-8e69-92b715f01ff8@p20g2000vbm.googlegroups.com> Content-Type: text/plain; charset="UTF-8" Organization: Team Rubber Date: Fri, 16 Dec 2011 13:33:14 +0000 Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 87.194.110.230 X-SA-Exim-Mail-From: tim.wintle@teamrubber.com X-SA-Exim-Scanned: No (on mail.netsight.co.uk); SAEximRunCond expanded to false Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: tim.wintle@teamrubber.com List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1324044351 news.xs4all.nl 6980 [2001:888:2000:d::a6]:60634 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:17354 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) Tim