Simple lock
MRAB
python at mrabarnett.plus.com
Fri Mar 19 22:31:23 EDT 2010
moerchendiser2k3 wrote:
> Hi,
>
> I have a common question about locks:
>
> class SetPointer
> {
> private:
> void *ptr;
>
> MY_LOCK lock;
>
>
> public:
> void SetPointer(void *p)
> {
> Lock(this->lock);
> this->ptr = p;
> }
>
> void *GetPointer()
> {
> Lock(this->lock);
> return this->ptr;
> }
> };
>
>
> Just a question, is this lock redundant, when the Pointer can be set/
> get from different threads?
> Thanks a lot!! Bye, moerchendiser2k3
1. That's C++. What does it have to do with Python?
2. The value you're accessing is a simple pointer which you're either
setting or getting, so a lock shouldn't be necessary.
3. You're locking, but never unlocking. The sequence should be: lock, do
stuff, unlock.
More information about the Python-list
mailing list