Solved Is it safe to send the message by QSslSocket in another thread
-
As the title mentioned. The scenario is
- I want to do heavy task in another thread, and send the message in the other thread directly since it is more convenient.
- I do not need to consider race condition in my case, no lock is needed.
Is this safe to do something like following?
pseudo codes:
socket_->write(process_result)
Or I better send the message in the main thread(the socket is created in the main thread)
emit sendMessage(process_result)
Thanks
-
So why not create the socket in the thread you want to send the data?
-
- Because I dumb the work into a QThreadPool
- it is not possible to open the server in every worker
- Those workers should be killed after the task are done
-
Is the socket closed after the work is done? If not then the best idea is to emit a signal (maybe as a QSharedPointer/Pointer) and send the data from the thread where the socket was created.
And btw: this sounds more a task for a QFuture