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

Issue with RawWakerVTable on crossing threads #120

Open
ihciah opened this issue Oct 24, 2022 · 2 comments
Open

Issue with RawWakerVTable on crossing threads #120

ihciah opened this issue Oct 24, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@ihciah
Copy link
Member

ihciah commented Oct 24, 2022

As a runtime of thread-per-core model, mostly we works like running multiple independent threads in parallel. So we implemented it in a non-thread-safe way. For example, when maintaining refcount of task, we use UnsafeCell<usize>.
There are 2 problems here:

  1. There is no non-Send + non-Sync version of Waker / RawWakerVTable. As the document of RawWakerVTable, all 4 functions must be thread safe.
    Since Waker and RawWakerVTable are all defined by std library and they impl Send and Sync, so we cannot restrict users not pass them between threads. Even we can tell users not pass them, this is not a rusty way. We'd better let it crash on compiling or running, or, we have to make it really thread-safe.
  2. We support a sync feature which implemented by passing waker that not belongs to current thread. This solves task execution problem on thread-per-core way, but the implementation itself is not thread safe. We have to transfrom the state in atomic way. The problems comes from the task module too, the same as the first problem. I believe problem create a VTable (raw_waker) in a thread 2 and call (wake_by_val) in thread 1 #117 is triggered by this problem.

So as a user, if you do not await across threads, you are not affected by the issue. The issue will be fixed soon.

@tvallotton
Copy link

I made a proposal here that I believe would benefit you. Sadly, it hasn't received a lot of attention. I would really appreciate if you could comment your thoughts on it.

@tvallotton
Copy link

Btw, the local_waker feature is already available on nightly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants