Next: , Up: Native Mode


13.1 Thread Model

Native mode programs are no longer realtime. There are two main concerns related to scheduling.

First, normal multitasking (the task_xxx APIs) is accomplished using the pth library, an open source, nonpreemptive thread library. A thin wrapper maps the core task APIs to their pth equivalents.

Periodic functions are called occasionally from a special thread instead of the FreeWPC scheduler.

Interrupts are also simulated from an ordinary thread. The native operating system probably does not allow threads to sleep for as little as 1ms; on Linux the minimum sleep time is on the order of 10-20ms instead, and under Cygwin, it may be even longer. When the interrupt thread is woken up, it checks the system clock to see how much time has actually elapsed, and invokes the interrupt handler multiple times. The net effect is that interrupt handlers are invoked the same number of times as they would be on real hardware, but not the same way: they are called in batches, rather than being equally spread out.

By default, the simulation runs at the same speed as the native system clock. It is possible to speed up the simulation by a constant multiplier, which is sometimes helpful for rapid testing.