The callback can be called synchronously or asynchronously. This is controlled by the glEnable flag GL_DEBUG_OUTPUT_SYNCHRONOUS. If this flag is enabled, then OpenGL guarantees that your callback will be called:
...
...
If the flag is disabled, then none of these are guaranteed. So if you want asynchronous debug output (for performance reasons), you must take into account the following possibilities:
...
Multiple instances of the same callback function may be called at the same time, obviously from different threads.
Right now it creates a mutable reference to the user data which requires exclusivity.
But https://www.khronos.org/opengl/wiki/Debug_Output#Getting_messages notes: