4 ms·
So thread unsafe?
by netheril96 8y ago
So thread unsafe?
- usefulcat 8y agoDefinitely
- tropo 8y agoIt doesn't have to be. It just is, because there is no need for the overhead of dealing with threads.
- romed 8y agoNote 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: int set_the_mtime(...) { static int starting_from = set_mtime_starting_from(0); set_mtime_starting_from(starting_from); } // Try various ways of setting mtime until it works. int set_mtime_starting_from(int starting_from) { // horrible switch statement }
- repsilat 8y agoIn 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...