Multi Threading

Does the imp support Multi Threading?

If so does someone have an example? I’m looking through the documentation, but I don’t see anything referencing it.

Think I found it. Correct me if I’m wrong there called Generators in Squirrel?

Let’s say I’m polling a temp sensor every 5 seconds to monitor a piece of hardware. Would it make sense to use a generator to perform a shutdown action when the temp rose about a certain threshold?

I’m new at this, so I’m thinking in terms of multiple threads, one that would monitor the system and perform an action on the main loop if something needed to be done. Not sure if this is beneficial on the imp or not?

Squirrel code running on the imp isn’t multi-threaded. There are several tricks you can perform to get almost parallel operation, but only one bit of code will ever be run at once.

If you need to poll every five seconds, and one reading warrants remedial measures, that’s not too difficult to trigger those measures and, if necessary, stop sensing the temperature until the connected hardware has restarted or whatever. This is one of the advantages of non-blocking loops.

Edit: if you’re not sure what I mean when I talk about non-blocking loops, take a look at this document: Looping the loop

If you are new to this I would not suggest generators. I think you can just call a function if the temperature is above a certain point.

You can have multiple imp.wakeup events queued at the same time. You can cancel them if you need to. There isn’t a main loop so what I have typically done is have one of my functions be a main one and it calls itself.