The code used a weird combination of c-style function points with c++ templates. Using FunctionRef allows writing the same code much simpler. I also removed the thread_id argument because it was never used.
No functional or performance changes are expected.