M
M
Matweytt2020-02-27 01:24:42
Qt
Matweytt, 2020-02-27 01:24:42

Does Qvector need a mutex?

There is a UDP class, a vector is defined in it (plays the role of a buffer), QUdpsocket is also defined, which is bound to the port and, at each signal, calls the function of reading data from the socket and then writing to the vector, there is also a couple of functions for receiving data from the vector.
The essence of the question is that I tested and if the vector is entered data from the socket and at the same time another function I receive data from the vector of the error does not occur. Whether it is necessary to be reinsured by a mutex?
Or what architecture to make different if a huge amount of data is sent to the socket and it cannot be processed in real time without a buffer))?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ighor July, 2020-02-27
@IGHOR

Any descendant of QObject is not thread safe.
Socket operations using QObject descendants from different threads are not safe, even with locks. To use a socket descriptor in any way in different threads, they must be unhooked from the controlling successor of QObject.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question