Desynchronizing / Synchronizing a thread while debug.profilebegin() is active breaks profiling, causing profileend to throw an error

When calling task.desynchronize() or task.synchronize(), it causes issues with debug.profilebegin(). When doing debug.profileend(), it throws a warning: debug.profileEnd() - No active profile annotation. This is very annoying for any code that is trying to profile desynced or synced code.