Skip to content

macos: *mut c_void cannot be sent between threads safe #1905

@hulxv

Description

@hulxv

Description

In Citadel-tech, we are working on an event-loop library, and it works without issues on Linux and Windows, but for some reason, it fails on MacOS (or kqueue generally, as I think). That happens because one of the Event attributes couldn't be sent safely between threads (See the opened issue about that citadel-tech/Event-Loop#68).

error message:

*mut c_void` cannot be sent between threads safely
    --> src/reactor.rs:73:24
     |
  73 |           self.pool.exec(move || {
     |                     ---- ^------
     |                     |    |
     |  ___________________|____within this `{closure@src/reactor.rs:73:24: 73:31}`
     | |                   |
     | |                   required by a bound introduced by this call
  74 | |             let entry = registry.get(&token);
  75 | |
  76 | |             if let Some(entry) = entry {
...    |
  85 | |         })
     | |_________^ `*mut c_void` cannot be sent between threads safely
     |
     = help: within `{closure@src/reactor.rs:73:24: 73:31}`, the trait `Send` is not implemented for `*mut c_void`
note: required because it appears within the type `libc::unix::bsd::apple::kevent`
    --> /Users/0xegao/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/libc-0.2.177/src/unix/bsd/apple/mod.rs:1322:16
     |
1322 |     pub struct kevent {
     |                ^^^^^^
note: required because it appears within the type `Event`
    --> /Users/0xegao/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/mio-1.0.4/src/event/event.rs:17:12
     |
  17 | pub struct Event {
     |            ^^^^^
note: required because it's used within this closure
    --> src/reactor.rs:73:24
     |
  73 |         self.pool.exec(move || {
     |                        ^^^^^^^
note: required by a bound in `ThreadPool::exec`
    --> src/thread_pool.rs:49:23
     |
  47 |     pub fn exec<F>(&self, task: F) -> Result<()>
     |            ---- required by a bound in this associated function
  48 |     where
  49 |         F: FnOnce() + Send + 'static,
     |                       ^^^^ required by this bound in `ThreadPool::exec`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `mill-io` (lib) due to 1 previous error

this happens here:

https://github.com/citadel-tech/Event-Loop/blob/16d70c6f524f6bde80bbbc42dd2209edb94de93f/src/reactor.rs#L68-L86

There are some solutions for our case, like making a safe wrapper that contains the important information, but I want to know if there are any solutions that can fix it internally in mio-rs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions