System thread
System threading behavior
When the system thread is enabled, application execution changes compared to non-threaded execution:
setup()
is executed immediately regardless of the system mode, which means setup typically executes before the Network or Cloud is connected.Particle.function()
,Particle.variable()
andParticle.subscribe()
will function as intended whether the cloud is connected or not.You should avoid calling
Particle.publish()
before being cloud connected as it may block. This is important if you are switching to threaded mode and previously published an event from setup.Other network functions such as
UDP
,TCPServer
andTCPClient
) should wait until the network is connected before use.After
setup()
is called,loop()
is called repeatedly, independent from the current state of the network or cloud connection. The system does not blockloop()
waiting for the network or cloud to be available, nor while connecting to Wi-Fi.System modes
SEMI_AUTOMATIC
andMANUAL
do not not start the network or cloud connection automatically, whileAUTOMATIC
mode connects to the cloud as soon as possible. Neither has an effect on when the applicationsetup()
function is run - it is run as soon as possible, independently from the system network activities, as described above.Particle.process()
anddelay()
are not needed to keep the background tasks active - they run independently. These functions have a new role in keeping the application events serviced. Application events are:- cloud function calls
- cloud events
- system events
- serial events
Cloud functions registered with
Particle.function()
and event handlers registered withParticle.subscribe()
continue to execute on the application thread in between calls toloop()
, or whenParticle.process()
ordelay()
is called. A long running cloud function will block the application loop (since it is application code) but not the system code, so cloud connectivity is maintained.- the application continues to execute during listening mode
- the application continues to execute during OTA updates
For additional information, see non-threaded system mode.