Draft: engine: move more code under loaders_lock
We need to always use the lock when checking the global loaders after they have been initialized.
This also adds a few more comments to clarify that the lock is already held in a few other functions where it would appear to be needed but isn't used.
This merge request also contains an unrelated commit to fix a sketchy loop termination condition.