#145 added a @global_compiler_lock to Dispatcher.compile(). This was my first iteration of a solution to the race in the dispatcher compilation.
There should be a compiler lock obtained in both compile() and compile_device(), and they should additionally start the compile timers, as in the CPU dispatcher: https://github.com/numba/numba/blob/1ba9c54e395e611bbe8d2dbe7a726488f5a75fbd/numba/core/dispatcher.py#L863-L877