Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yield(), esp_yield() or delay(0) ? #1950

Closed
s0170071 opened this issue Oct 23, 2018 · 13 comments
Closed

yield(), esp_yield() or delay(0) ? #1950

s0170071 opened this issue Oct 23, 2018 · 13 comments
Labels
Category: Stabiliy Things that work, but not as long as desired Type: Discussion Open ended discussion (compared to specific question)

Comments

@s0170071
Copy link
Contributor

@TD-er just found this: esp8266/Arduino#5254
Apparently there is a difference between the three. And using the wrong one has the potential to crash the system. Were you aware of this ?

I still need to dig deeper.
If you know something about this, please enlighten me.

@TD-er
Copy link
Member

TD-er commented Oct 23, 2018

I already used esp_yield() in a call.

The main different is that esp_yield will test if it is being run from cont stack or system stack.
So it is a safe call to yield for use in callback functions, since they may or may not be run from cont stack.
This will only make a difference if the error is about incorrect use of yield.

Not sure what the delay(0) does different from delay(1), apart from probably being 1 msec faster ;)

@uzi18
Copy link
Contributor

uzi18 commented Oct 23, 2018

esp_yield(): ESP8266Ping only
there are quiet some places where delay(1) could be changed into delay(0), as we not need delay but be sure system is stable.

@TD-er
Copy link
Member

TD-er commented Oct 23, 2018

There are not that many places anymore where we are calling delay with 1, are there?

@ascillato
Copy link

in the Arduino core, they change a yield() for esp_yield() and the webserver got unresponsive.

See esp8266/Arduino#5259

So, a delay(0) was the solution there to avoid the issue.

@uzi18
Copy link
Contributor

uzi18 commented Oct 23, 2018

@TD-er 110 places only in ESPEasy, did not count in libraries

@TD-er
Copy link
Member

TD-er commented Oct 23, 2018

OK, good to know.
I will have to look at the source code to see what is the difference between delay(0) and yield(), although I have some idea, but maybe not yet all the details present.
@ascillato do you have a link already? Otherwise I will have a look tomorrow.

Edit:
Found it:
https://github.com/esp8266/Arduino/blob/74819a763bfb6e9890a57411dcea4aba221a778d/cores/esp8266/core_esp8266_wiring.c#L43-L54

@TD-er
Copy link
Member

TD-er commented Oct 24, 2018

@ascillato
Is it possible the core library has changed in such a way that delay(0) does feed the watchdog timer and yield() no longer does?
I that is true, then what is the use for yield() compared to delay(0) ?

TD-er added a commit to TD-er/ESPEasy that referenced this issue Oct 24, 2018
`delay(0)` is a special case of delay, which also calls the system scheduler, `yield()` does not call.
It may interrupt a bit more than `yield()` 

See letscontrolit#1950
@ascillato
Copy link

@TD-er I really don't know. Sorry. May be we need to ask that to Arduino Guys.

@s0170071
Copy link
Contributor Author

Maybe @d-a-v or @earlephilhower can shed some light on the difference between esp_yield(), yield() or sleep(0) They were participating in the issue referenced in the first post.

@d-a-v
Copy link

d-a-v commented Oct 26, 2018

Maybe an issue should be opened in the core repository, with the very same title.
Simple answer is: do not use esp_yield(). Calling yield() in ISR or some callbacks will panic(). Calling delay(0) has the yield() effect without panicing but is missing the cont_check test.
Hopefully igrr would comment on this.

@Grovkillen Grovkillen added Type: Discussion Open ended discussion (compared to specific question) Category: Stabiliy Things that work, but not as long as desired labels Oct 30, 2018
@Grovkillen
Copy link
Member

I will close this, open if its still a valid issue.

@G2G2G2G
Copy link

G2G2G2G commented May 24, 2023

was this different years ago? delay(0) won't call yield at all, delay(1) would though

@TD-er
Copy link
Member

TD-er commented May 25, 2023

was this different years ago? delay(0) won't call yield at all, delay(1) would though

As far as I can remember, there was indeed a difference between delay() and delay(n), regardless the value of n.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Stabiliy Things that work, but not as long as desired Type: Discussion Open ended discussion (compared to specific question)
Projects
None yet
Development

No branches or pull requests

7 participants