+ Implemented timeouts for Windows using TimerQueueTimers.
+ Modified the implementation of timer for Posix systems. Instead of using ALRM signals, I create a new thread.
This simplifies the code, since both Posix and Windows implementations use a special thread to call AlarmCallback(). Under this assumption, we can safely use locks to synchronize that thread with the main thread. (We couldn't do that if the same code could be executed asynchronously by a signal handler in Posix systems and by a separated thread in Windows). Also, I realized that previous implementation assumed that the ALRM signals would be handled by the main thread, which is not necessarily true. In POSIX it is unspecified with thread handle signals.
+ I added a new flag RunningCB to know if the Fuzzer's main thread is running the CB function, instead of using ! CurrentUnitSize. ! CurrentUnitSize doesn't work properly.
For example, in FuzzerLoop.cpp, line 452, we execute the callback with size 0. Previous implementation failed to detect timeouts in that execution.
+ Add a mutex RunningCBMtx to synchronize the access to the Fuzzer's data between different threads.
All the information related to the state of the fuzzer is only modified by the main thread, when it is not running the callback function. So, in order to consistently access to the Fuzzer's data, we should lock the `RunningCBMtx` and make sure `RunningCB` is true (the main thread is running the CB). This is used to synchronize the thread which manages the timers, and the one which supervises rss limits, with the main thread.
It seems like we could use std::atomic_bool here. Does that not work for some reason? The only thing I see that is questionable is that in FuzzerCallback::CrashCallback we check the value, and then run multiple lines of code before returning.
But on the other hand, in Fuzzer::ExecuteCallback, we always set it to true before executing any callback, and false after. So maybe there is no race condition?
atomic_bool is more lightweight than grabbing a full blown mutex, so if we can be sure it's safe, then it seems better.