I am trying to use my WiFi RS9110 board with FEZ Cobra II. It works fine when I initialize the board in the main process thread. But as soon as I move the initialization logic into a thread (to do all the work in the background), I get HardwareTimeoutException. My board is updated to the latest firmware available. Has anyone seen this kind of a behavior? Is it ‘forbidden’ to initialize the WiFi from a separate thread?
thread.sleep(20) is a good idea - but a better idea is to use an appropriate delay that is suitable for your code/application. if you use (0) it at least causes a context switch so it will give up the processor if another thread needs time.
All threads should at some point yield with a sleep or you will deadlock as NETMF is not pre-emptive. Used 0 if your thread needs to run faster. 20ms for example is approx 20 characters on a 9600 bps serial port.
After thourough inspection, I’ve found a simple sample that results in the HardwareTimeoutException. Surprisingly, it is caused by the TimerCallback. The following snippet will block WiFiRS9110.Open call until the TimerCallback action exits. Here are the related call stacks (I don’t know how to get more detailed call stack information for NETMF runs):
Mike, I was not aware that the system event processing is single threaded, but guessed it was the case with the Timer experiment. The PubSub will obviously solve the issue here, but it sort of takes me back to the Symbian OS times where all the processing should have been single-threaded and take as little time as possible.
What are good multi-threading practices on G120 board? Is there a limit on the amount of threads that badly degrades the performance due to context switching? I just don’t want to do PubSub as it reduces the readability and future maintainability of the code