Better handling of context switches in runtime