Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

wasi_snapshot_preview2 - lack of sched_yield interface #582

Open

Description

@loganek

Hi all,

I'm looking to migrate some of the WSP1 code to WSP2 and I noticed there's no sched_yield equivalent in any of the existing world launched here: #577. Is this functionality covered by any of the existing proposals? I'm not sure if that's in scope of the https://github.com/WebAssembly/shared-everything-threads proposal, but even if so, the proposal is in a very early stage right now, but WSP2 is already launched.

My assumption was that WSP1 can be implemented using WSP2 (not other way around though) and that assumption was confirmed yesterday during the WASM64 discussion. I wonder if lack of the interface is simply a miss or was it deliberately omitted?

Thanks

Activity

  1. lukewagner commented on Feb 9, 2024

    @lukewagner
    Member

    I expect it was just an omission, but I do increasingly think (especially in concurrent composition scenarios like we're considering for Preview 3) that a cooperative "yield" call is pretty important, so maybe this could be a candidate for inclusion in the short term (wasi:io seems like the right place) as part of 0.2.1?

  2. lukewagner commented on Feb 9, 2024

    @lukewagner
    Member

    I suppose one short-term 0.2.0 workaround (which is not ideal, but probably gives the runtime what it needs to perform a cooperative yield) is to implement sched_yield with a wasi:io/poll.poll waiting on a pollable produced by wasi:clocks/monotonic-clock.subscribe-duration(0).

  3. pchickey commented on Feb 9, 2024

    @pchickey
    Contributor

    Agree with Luke -we omitted sched_yield because we weren't aware of any Preview 1 implementations or programs making strategic use of it, and didn't want to commit ourselves to something before we understood how its use would fit in with the rest of wasi-io and whatever other concurrency plans are upcoming in preview 3. Polling on an elapsed timer is a fine polyfill for now, and we'll add something more appropriate as the design space gets fleshed out better.

  4. sunfishcode commented on Mar 15, 2024

    @sunfishcode
    Member

    Another reasonable polyfill is to have sched_yield do nothing.

    As background here, sched_yield was derived from CloudABI. We defaulted to leaving it in because it was easy to implement and it didn't seem to have any obvious complications. However, I'm not aware of any meaningful use cases for it, especially since WASIp2 doesn't support threads yet.

  5. loganek commented on Mar 17, 2024

    @loganek
    Author

    I think it'd be helpful for projects that continue using wasi threads with preview 2.

  6. added
    S-inactive
    on Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    S-inactive

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions