You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This patch tests that the hook actually works. Not going to lie, the
test is pretty disgusting. The function we're testing is a noreturn
function, which introduces some interesting challenges when we need to
return to finish the test.
I need to somehow exit the function without killing the process, but
also without returning. If I just use a loop properly, the test will
hang for the age of the universe. If I don't and return from the hook,
the test will abort or crash. I tried removing the abort after the hook
in the hook override macro to see if we could sneak past the compiler,
and no, that explodes on the return pointer.
So, here's the workaround. C++11 threads don't seem to have a way to
kill themselves, but you can use `pthread_exit` or `pthread_kill` to
either kill yourself or kill another thread. So the override function
sets the `Ran` to true, and then exits (which is noreturn, so we haven't
broken that contract), killing itself and allowing us to join without
returning from the inferior. The main thread immediately waits for the
original thread to die. Since it blocks, we avoid the possible race on
setting the state of `Ran` in the override hook and where it gets
checked in the test. If that becomes an issue, we could probably just
wrap the `Ran` bool in an atomic and call it a day.
Anyway, it's well past my bedtime and I'm playing with threads. This can
only end in a creative disaster. :D
0 commit comments