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. Thread optimization issue
QtWS25 Last Chance

Thread optimization issue

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.3k 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.
  • R Offline
    R Offline
    RohitIti
    wrote on last edited by
    #1

    Hi guys,
    i need help in deciding the correct way of managing threads.

    Problem description :
    I have a xml file containing some messages with id and a cycle time for each message.
    The cycle time tells at what rate the messages should keep sending. Here lets take the total
    number of messages as 100.
    my requirement is that, i will get notification from outside (lets take it as some programme
    triggering the message id) every time i get the message with id from outside i need to search
    for that id in xml file and keep on sending the message to some other class for every cycle time of that message. This can be handled by timer and keep one sending the message.

    but my problem is for every message am creating a new thread and sending which is not good.
    can some tell me some thread optimization here so that it can be easily handled in later stages also.

    XML File
    @
    <id>1</id>
    <msg>hello</msg>
    <cycle>1000</cycle>

             <id>2</id>
      <msg>hello Qt</msg>
             <cycle>1000</cycle>
                    .
                    .
                    .
    

    @

    @
    class xmlparser() -------> reads xml file.
    class MessageSender() -------> sends the message to class RecieverMessage.
    class RecieverMessage() ----------> getmessage(id) , recieves the message,
    searches the id in xmlparser and keep on creating thread and sends the message.
    @

    [andreyc EDIT]: Added @ around code.

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      How are you creating thread ? Did you inherit from QThread or using QRunnable ? You need to some kind of ThreadPool to manage number of threads what you create. There is QThreadPool and which works with only QRunnable. This can be used only if you don't want any signal/slot communication with your thread objects. Do you need to communicate back from threads to main UI ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andreyc
        wrote on last edited by
        #3

        [quote author="Dheerendra" date="1410348149"]There is QThreadPool and which works with only QRunnable. This can be used only if you don't want any signal/slot communication with your thread objects.[/quote]

        It is not quite true.
        You can inherit your class from "QObject and QRunnable":http://qt-project.org/forums/viewthread/22030/#104010 to get signal slot communication.

        1 Reply Last reply
        0
        • R Offline
          R Offline
          RohitIti
          wrote on last edited by
          #4

          Hi ,

          Thank you for your reply Dheerendra and andreyc,

          I have inherited class from QThread and i need signal / slot communication.
          so what kind of optimization i can do in this case

          1 Reply Last reply
          0

          • Login

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