3 ms·
What if I use a library that forks or spawns threads? It would know nothing about these counters and wouldn't increment them, so I'd never know. That's the ne
by adamtj 11y ago
What if I use a library that forks or spawns threads? It would know nothing about these counters and wouldn't increment them, so I'd never know.
That's the neat thing about the original article: you can know if a fork happened outside of your own code.
- geofft 11y agoAs agwa pointed out, it does work, but with a different definition of work (i.e., a different use case). The use case is for, say, a callback that might be called from different sides of fork, but shouldn't be. If you run this algorithm at the top of your callback, one side of fork will arbitrarily be okay, but the other side of fork will report a discrepancy between the two values. For some applications, that's all you need to know. If the forking library never calls into your code from two different sides of fork, then that's fine (for this use case), and your algorithm will never detect a fork: as long as your code is only called from one side of every fork, the two numbers will stay in sync. The use case is something like a random seed, where you don't want to branch the same seed into two timelines. If you follow only one timeline, that's acceptable, even if there are other timelines. (This algorithm doesn't handle multiple threads either, I think.)
- geocar 11y agoMultiple threads will share the random state, and won't cause a problem there.