links
August 25th, 2010, 02:55 AM
From a multithreaded and multi-processor/core perspective, what would be safer, pass-by-value or pass-by-reference?
I know there's no hard and fast rules, but what would you consider as a general guideline?
To me it feels that pass-by-reference is more risky in a multithreaded environment. Another thread can modify an object while a function is busy operating on it. Using pass-by-value decreases the chance of a mess happening. The downside of course is the overhead associated with passing large objects by value.
I know there's no hard and fast rules, but what would you consider as a general guideline?
To me it feels that pass-by-reference is more risky in a multithreaded environment. Another thread can modify an object while a function is busy operating on it. Using pass-by-value decreases the chance of a mess happening. The downside of course is the overhead associated with passing large objects by value.