Increasing the counter in a new thread transmitted by an object is almost certainly incorrect. An arbitrary amount of code in the "parent" thread can be executed before the new "child" thread is launched at all, in which case the function in the "parent" thread can return, make other material, reduce the number of links to 0, and free the object. The new thread then touches the invalid memory, causing undefined behavior, and all hell breaks.
Please note that such errors will probably not be detected for a long time, as it is statistically unusual for a new thread that does not start immediately. In fact, it will probably be your clients / clients who first find the error ... :-)
source share