Question

I think I already know the answer to this, but I'm currently working on re-vamping some legacy Visual C++ 6.0 code, and I was working on putting in some CCriticalSections, But then I got thinking about it, if all my function does is return a pointer to some data, I think the critical sections is probably useless, because I don't think im really protecting the data its pointing too, I don't think it really stops anyone from writing to it. (assuming i have the same locks around the setter).

What do you think?

Was it helpful?

Solution

Yes if you are returning pointers to a data then deferencing the pointers outside the critical section would be a problem. Access to the critical shared data must be within the locks.

OTHER TIPS

I'm not sure what you mean by CCritialSections, but in general, functions that return pointers or references are not good candidates for mutex locking. You need to manage things at a higher level.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top