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


Groups > comp.programming.threads > #533

Re: Thread Safety of "this" pointer

From Sergei Organov <osv@javad.com>
Newsgroups comp.programming.threads
Subject Re: Thread Safety of "this" pointer
Date 2011-09-05 21:46 +0400
Organization Aioe.org NNTP Server
Message-ID <j431tr$8e6$1@speranza.aioe.org> (permalink)
References <j40c4l$gnt$1@dont-email.me>

Show all headers | View raw


ittium <ittium@gmail.com> writes:

> Group,
> There is a base class B and Two derived class D1 and D2. b is
> **shared** base class pointer. While d1 and d2 are derived class
> pointer
>
> thread 1
> --------
> *b=d1;
> b->execute();
>
> thread 2
> --------
> *b=d2;
>
> Should I protect (using mutex) the above code. Since this pointer will
> change during the processing
> thanks
> Ittium

Yes, you should implement protection to the above code, but no, 'this'
pointer won't be changed during processing. It's contents of the
variable to which 'b' points that will be changed, and it's that
contents you need to protect (using mutex).

-- Sergei.

Back to comp.programming.threads | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Thread Safety of "this" pointer ittium <ittium@gmail.com> - 2011-09-04 22:52 +0530
  Re: Thread Safety of "this" pointer David Schwartz <davids@webmaster.com> - 2011-09-04 15:31 -0700
    Re: Thread Safety of "this" pointer itt ium <ittium@gmail.com> - 2011-09-05 01:43 -0700
      Re: Thread Safety of "this" pointer ycwang <wangyongcong@gmail.com> - 2011-09-05 03:21 -0700
  Re: Thread Safety of "this" pointer Sergei Organov <osv@javad.com> - 2011-09-05 21:46 +0400

csiph-web