News for hackers. Stuff that matters.
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:

  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
  }
Re:A fun optimization trick from rsync by repsilat on Sunday October 28, 2018 @11:00PM (#18324733)
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...