[Interest] QMap and thread-safe.

Sze Howe Koh szehowe.koh at gmail.com
Wed Jul 24 10:31:49 CEST 2013


On 24 July 2013 15:29, Mandeep Sandhu <mandeepsandhu.chd at gmail.com> wrote:
> Also, doesn't a "const" (old sense of the word) member function mean - "I'm
> not going to alter the state of the object" ?
>
> If so, that would make it thread-safe in the special scenario (mentioned by
> OP) where only "reads" are being attempted, right? Can an implementation
> make it thread-unsafe while still being const (again considering only the
> special "read-only" scenario)?

A const method can't affect other threads, but other threads can
affect a const method.

Suppose a const function is reading a large data object. If the object
wasn't locked, other threads could modify it while the first function
is in the middle of reading it, potentially corrupting the result of
the first function.


Sze-Howe



More information about the Interest mailing list