Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Is it safe to send the message by QSslSocket in another thread
Forum Updated to NodeBB v4.3 + New Features

Is it safe to send the message by QSslSocket in another thread

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 386 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • thamT Offline
    thamT Offline
    tham
    wrote on last edited by
    #1

    As the title mentioned. The scenario is

    1. I want to do heavy task in another thread, and send the message in the other thread directly since it is more convenient.
    2. 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

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      So why not create the socket in the thread you want to send the data?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      thamT 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        So why not create the socket in the thread you want to send the data?

        thamT Offline
        thamT Offline
        tham
        wrote on last edited by
        #3

        @Christian-Ehrlicher

        1. Because I dumb the work into a QThreadPool
        2. it is not possible to open the server in every worker
        3. Those workers should be killed after the task are done
        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved