axboe / liburing

Library providing helpers for the Linux kernel io_uring support
MIT License
2.87k stars 402 forks source link

Is io_uring funcs can be call in other thread? #604

Closed richard0326 closed 1 month ago

richard0326 commented 2 years ago

Hello I'm trying to use IO_uring and not used to it I have tried all the echo severs of every open sources. So I know the basic uses.

This is my problem! This is what I have tried and doesn't work!!

= what I have done = I have a cqe loop thread. I call it "CompleteIOThread". And have another thread. Call it "SubmitThread".

I will wait some cqes in my CompleteIOThread by using 'io_uring_wait_cqe' or some kind. And after cqe comes, and thread will start. I will solve with cqe (use 'io_uring_cqe_seen') and make another sqe but not in this thread. I will toss some cqe result to SubmitThread and SubmitThread will do some logics and then use sqe.

something like this (code in SubmitThread) " struct io_uring_sqe *sqe = io_uring_get_sqe(_ring); if (sqe == nullptr) { cerr << "Warning Fail\n"; } else { io_uring_prep_read(sqe, _fd, _buffer, _bufferSize, 0); io_uring_submit(_ring); } " 2 thread has same ring. And Submit thread can be scale out! or Opersite(CompleteIOThread can be scale out)

Is it not posible to use 'io_uring func' in different thread?? Because it keep returning nullptr in sqe and I have no idea to look!

richard0326 commented 2 years ago

I'm checking if 'io-uring func' is thread safe

CarterLi commented 2 years ago

I'm checking if 'io-uring func' is thread safe

liburing func is not thread safe, io-uring func is. That means, you must use syscalls ( io_uring_setup, io_uring_enter ... ) with io_uring fd directly