Make a small function thread safe

Tim Wintle tim.wintle at teamrubber.com
Fri Dec 16 08:33:14 EST 2011


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




More information about the Python-list mailing list