Skip to content

Use sched_yield() as fallback for preemption yield #459

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

Merged
merged 1 commit into from
Mar 21, 2019
Merged

Use sched_yield() as fallback for preemption yield #459

merged 1 commit into from
Mar 21, 2019

Conversation

triplef
Copy link
Contributor

@triplef triplef commented Mar 19, 2019

pthread_yield() is not available on Android.

In combination with #458 this fixes all build issues using Android NDK targeting API level 21 and up.

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wont work. #453 fix the Windows path to use Sleep(0);

@triplef
Copy link
Contributor Author

triplef commented Mar 19, 2019

I see. I’ll wait for #453 to be merged and re-do the this to also use sleep on Android.

@triplef
Copy link
Contributor Author

triplef commented Mar 20, 2019

I’ve updated the patch to use sleep(0) if pthread_yield_np() is not available.

@adierking
Copy link
Contributor

Using sleep(0) to yield on non-Windows systems isn't correct because there's no guarantee that it will actually do anything (and in fact some versions of glibc will return immediately). The Windows path uses it because Microsoft explicitly documents that Sleep(0) relinquishes the thread's timeslice. The correct fallback should be sched_yield(), which is mandated by POSIX.

@triplef
Copy link
Contributor Author

triplef commented Mar 20, 2019

@adierking that’s what I thought and had used originally. :-) Just to confirm, would you use sched_yield() just on Android or everywhere as a fallback?

@adierking
Copy link
Contributor

@adierking that’s what I thought and had used originally. :-) Just to confirm, would you use sched_yield() just on Android or everywhere as a fallback?

I think it should be used as a fallback everywhere. Nothing should be using pthread_yield() anymore because sched_yield() is a standardized function which accomplishes the same thing.

@triplef
Copy link
Contributor Author

triplef commented Mar 20, 2019

Great, I updated the patch to use sched_yield().

@triplef triplef changed the title Use sched_yield() on Android Use sched_yield() as fallback for preemption yield Mar 20, 2019
@compnerd
Copy link
Member

@swift-ci please test

@ktopley-apple
Copy link
Contributor

@swift-ci please test

1 similar comment
@compnerd
Copy link
Member

@swift-ci please test

@ktopley-apple ktopley-apple merged commit 9d485ca into swiftlang:master Mar 21, 2019
rokhinip pushed a commit that referenced this pull request Nov 5, 2021
Use sched_yield() as fallback for preemption yield

Signed-off-by: Kim Topley <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants