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. QPluginLoader thread safety question

QPluginLoader thread safety question

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 5 Posters 591 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.
  • G Offline
    G Offline
    gani.cahyono
    wrote on last edited by
    #1

    Hi,

    I have question about QPluginLoader thread safety.
    For example, I have 3 objects, each have QPluginLoader instance and all 3 load the same plugin.
    Each object are running on separate thread.
    Is this safe? Does QPluginLoader make sure the thread safety during load and unload?

    jsulmJ 1 Reply Last reply
    0
    • G gani.cahyono

      Hi,

      I have question about QPluginLoader thread safety.
      For example, I have 3 objects, each have QPluginLoader instance and all 3 load the same plugin.
      Each object are running on separate thread.
      Is this safe? Does QPluginLoader make sure the thread safety during load and unload?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @gani-cahyono Why do you want to load a plug-in more than once?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

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

        @gani-cahyono said in QPluginLoader thread safety question:

        Does QPluginLoader make sure the thread safety during load and unload?

        Rule of thumb: if the class / function does not mention that it's thread-safe then it isn't.

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

        G 1 Reply Last reply
        4
        • G Offline
          G Offline
          gani.cahyono
          wrote on last edited by
          #4

          @jsulm said in QPluginLoader thread safety question:

          @gani-cahyono Why do you want to load a plug-in more than once?

          The objects are different classes that need to use the functions from the same plugins.
          The classes doesn't each other so passing around plugins might introduce some kind of coupling.

          J.HilkJ 1 Reply Last reply
          0
          • G gani.cahyono

            @jsulm said in QPluginLoader thread safety question:

            @gani-cahyono Why do you want to load a plug-in more than once?

            The objects are different classes that need to use the functions from the same plugins.
            The classes doesn't each other so passing around plugins might introduce some kind of coupling.

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @gani-cahyono
            I think you're either over thinking this, or you're not doing your due diligence with your dlls

            Do you use some kind of shared memory in your dll ?
            No? than you're fine.
            Yes ? Mutex the access, but keep in mind, "Dlls may be mapped in at different addresses in each process space. If so, all pointers will be incorrect."


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            1
            • Christian EhrlicherC Christian Ehrlicher

              @gani-cahyono said in QPluginLoader thread safety question:

              Does QPluginLoader make sure the thread safety during load and unload?

              Rule of thumb: if the class / function does not mention that it's thread-safe then it isn't.

              G Offline
              G Offline
              gani.cahyono
              wrote on last edited by gani.cahyono
              #6

              @J-Hilk said in QPluginLoader thread safety question:

              @gani-cahyono
              I think you're either over thinking this, or you're not doing your due diligence with your dlls

              Do you use some kind of shared memory in your dll ?
              No? than you're fine.
              Yes ? Mutex the access, but keep in mind, "Dlls may be mapped in at different addresses in each process space. If so, all pointers will be incorrect."

              Sorry, maybe I was not being clear. My question is not about the dll itself.
              It's about QPluginLoader load/unload function. For example, if a QPluginLoader of plugin A in thread 1 is loading (load function hasn't return), then at the same time QPluginLoader of plugin A in thread 2 also calling load, is this safe?

              https://doc.qt.io/qt-5/qpluginloader.html stated

              The instance() function implicitly tries to load the plugin if it has not been loaded yet. Multiple instances of QPluginLoader can be used to access the same physical plugin.

              This mean, multiple QPluginLoader to the same plugin should return the same instance. But I'm not sure about thread safety the load/unload function.

              @Christian-Ehrlicher said in QPluginLoader thread safety question:

              Rule of thumb: if the class / function does not mention that it's thread-safe then it isn't.

              I guess it is not thread safe. Thanks.

              1 Reply Last reply
              0
              • nageshN Offline
                nageshN Offline
                nagesh
                wrote on last edited by nagesh
                #7

                @gani-cahyono

                Once loaded, plugins remain in memory until all instances of QPluginLoader has been unloaded, or until the application terminates. You can attempt to unload a plugin using unload(), but if other instances of QPluginLoader are using the same library, the call will fail, and unloading will only happen when every instance has called unload()
                

                As per Qt doc

                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