c - What is the rule of thumb for incrementing reference counts? -


when sending reference counted objects other threads, better better rule of thumb increment count before launching thread or within thread?

in more general sense, should (as function) assume parameters passed me accounted or not?

incrementing count within new thread pass object wrong. arbitrary amount of code in "parent" thread may run before new "child" thread gets run @ all, in case function in "parent" might return, other stuff, decrement reference count 0, , free object. new thread touch invalid memory, invoking undefined behavior, , hell break lose.

further note such bugs go undetected long time, since it's statistically unusual new thread not run immediately. in fact customers/clients see bug first... :-)


Comments

Popular posts from this blog

Cursor error with postgresql, pgpool and php -

delphi - ESC/P programming! -

c++ - error: use of deleted function -