Re:A fun optimization trick from rsync
by romed on Sunday October 28, 2018 @10:43PM
(#18324641)
Note that if this were C++ (11 or later) this could be done with the static variable in a thread-safe way, since function-scoped static variables initialized by functions are guaranteed to be initialized exactly once. So this code could be something like:
[ Parent
| on HN ]
In C++ you could also make an object (per thread?) and use member vars instead of static vars.
Also, if you're going to use static vars in multithreaded contexts doing this, better to write
thing = 5;
(via that macro magic) than `thing++`. Then at least nothing too bad should happen...