Skip to content

How to safely submit operations from another thread while a thread is blocked on io_uring_submit_and_wait_timeout? #1478

@just-language

Description

@just-language

I'm building an io loop around io uring and the app waits for pending completions using io_uring_submit_and_wait_timeout but sometimes I want to just interrupt the wait or submit another operations from another thread since clearly the thread calling io_uring_submit_and_wait_timeout is blocked.

My options:
1- Use locks: but how can I hold the lock across call to io_uring_submit_and_wait_timeout and at the same time hold the same lock when calling io_uring_get_sqe and io_uring_submit from another thread? I used this at first but it clearly caused a deadlock!

2- Use a rings per thread: I don't know how submitting a request on a ring will unblock io_uring_submit_and_wait_timeout on another ring, or I'm missing something?

3- Use io_uring_register_eventfd and use epoll with another interrupter eventfd and wait for both the ring and interrupter using epoll_wait. I used this and it works well since no need at all to wait on the ring. but I'm trying to use io uring without epoll at this moment.

4- just call io_uring_submit_and_wait_timeout or io_uring_wait_cqe without holding a lock and call io_uring_get_sqe and io_uring_submit from another threads (a lock may be used for the submission but not for waiting thread) and hope it just works fine. I'm currently using this and it seems to work. Also I saw asio calling io_uring_wait_cqe without holding the lock. Is this officially supported?

5- I think this is supported: separate submission from waiting so hold a lock for submission but not for waiting and use io_uring_submit to submit the pending SQ entries then use io_uring_get_sqe to get the CQEs since the submission buffer is independent from the completion buffer this should just work. I think asio is actually doing this not option 4.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions