Some refactoring in task switching code and sync API, task switches are now atomic (as they should be in a first time)