Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #17354

Re: Make a small function thread safe

Subject Re: Make a small function thread safe
From Tim Wintle <tim.wintle@teamrubber.com>
References <10d3d04f-1708-4942-8e69-92b715f01ff8@p20g2000vbm.googlegroups.com>
Organization Team Rubber
Date 2011-12-16 13:33 +0000
Newsgroups comp.lang.python
Message-ID <mailman.3726.1324044351.27778.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Make a small function thread safe Brad Tilley <kj4eit@gmail.com> - 2011-12-16 05:21 -0800
  Re: Make a small function thread safe Tim Wintle <tim.wintle@teamrubber.com> - 2011-12-16 13:33 +0000
  Re: Make a small function thread safe Tim Wintle <tim.wintle@teamrubber.com> - 2011-12-16 14:36 +0000
    Re: Make a small function thread safe Brad Tilley <kj4eit@gmail.com> - 2011-12-16 07:05 -0800
  Re: Make a small function thread safe Lie Ryan <lie.1296@gmail.com> - 2011-12-17 09:08 +1100
    Re: Make a small function thread safe John Nagle <nagle@animats.com> - 2011-12-16 18:18 -0800
      Re: Make a small function thread safe RangerElf <gustavo.cordova@gmail.com> - 2011-12-18 00:52 -0800
        Re: Make a small function thread safe Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-18 23:57 -0700
  Re: Make a small function thread safe ting@thsu.org - 2011-12-19 15:56 -0800

csiph-web