H
H
HamsterGamer2022-02-23 13:36:22
ASIO
HamsterGamer, 2022-02-23 13:36:22

Is it possible to run io_service::run in parallel?

I have a rather large code in which the sanitizer detects the data race. In this code, I use mutexes in every method of my network interface class that stores/creates its socket for itself, something like this:

struct NetRequster {
//...
   void some_work_if_recive();  
   void some_work_if_timeout();
// ...
private:
   ba::ip::tcp::socket socket_;
   std::mutex m;
// ...
};

If the data arrives, then the some_work_if_recive method is called, which will do something and subsequently cut down all operations with its class using a boolean flag, if the data does not arrive within a certain time, then some_work_if_timeout is called, which will call the close method on the socket, and all these the data will always be under the mutex, but it is planned to parallelize the work of separate NetRequster. On the other hand, having created many such requesters, I simply run io_service::run in N threads.
However, io_service somewhere checks whether the socket is open using the is_open method, which in turn is not closed by my mutex and leads to a date flight. I don’t think that this is normal, but it turns out that paralleling won’t work at all, tell me what I’m doing wrong or how it should look like in reality? Maybe even have an example of what I want!
Here's what the sanitizer says:
62160dd4ed5ce396847242.png62160ddb6edd1023118470.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question