Skip to content

Issue with RawWakerVTable on crossing threads #120

@ihciah

Description

@ihciah

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions