Syscall::yield operation

Hi,

so i keep seeing code like this in other projects:

Serial.println(“Type any character to start”);
while (Serial.read() <= 0) {
SysCall::yield();
}

but i cant seem to find any reference to SysCall::yield() in the particle reference material. I know that this function waits for the user to enter a character before proceeding, but not sure just what the SysCall::yield() is yielding. It appears to be an Arduino thing, but it does work on the photon.

Is it something i should be doing on the Photon, or will it cause me trouble down the road? can anyone point me in the right direction?

thanks

Can you point to specific projects that we can look at?

I have seen similar code in libraries where yield() is a common placeholder for platform specific “maintenance” tasks. In the Particle ecosystem that would be Particle.process().

In this particular instance it’s probably from SDFat library

2 Likes

The particular implementation of “yield()” is platform specific. However, in general, this function is meant to tell the scheduler in a multi-threaded system that you are OK with giving back your time slice of the processor to other threads at this point. Its use is usually something like a polling thread that is checking on the status of other threads by looking at a boolean flag or something. The idea would be to check the flag, and if it is not set to call yield(). Although yield() is not really required to do anything, usually the thread implementation will give back the remainder of your time slice to other threads. This can increase the overall performance of a program structured like this.

When would you use it? Generally, unless you are specifically using the RTOS to spawn threads and wish to monitor them from other threads, you would have no need to use yield().

1 Like

I did find it in the greiman/SdFat lib.

From the discussion above, i believe i understand what it is doing. Thanks for all the info.