Regular API function

sim.setThreadAutomaticSwitch

Description Allows to temporarily forbid automatic thread interruptions, i.e. preemptive threading. Explicit thread interruptions, i.e. switching, are still allowed. For complete control over thread switching, see also sim.getThreadAutomaticSwitch, sim.setThreadSwitchAllowed, sim.setThreadSwitchTiming and sim.switchThread.
C synopsis
C parameters
C return value
Lua synopsis int autoSwitchForbidLevel=sim.setThreadAutomaticSwitch(boolean allowAutoSwitch / int forbidLevel)
Lua parameters
allowAutoSwitch: if false, then the thread will not be automatically interrupted anymore (i.e. automatic thread switching will be temporarily disabled). Calling n times sim.setThreadAutomaticSwitch(false) requires to call n times sim.setThreadAutomaticSwitch(true) to restore the initial behaviour.
forbidLevel: allows to set an auto switch forbid level: a level > 0 indicates that automatic thread interruption is disabled.
Best is to always use following to temporarily forbid automatic thread interruptions:
local initialForbidLevel=sim.setThreadAutomaticSwitch(false) -- forbid automatic thread switches
...
sim.setThreadAutomaticSwitch(initialForbidLevel) -- restore to initial state
Lua return values
autoSwitchForbidLevel: the forbid switch level before calling the function, i.e. the forbid switch level that should be restored later on.