Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MFC Thread queue size

MFC Thread queue size

Scheduled Pinned Locked Moved C / C++ / MFC
c++data-structuresjsonquestion
10 Posts 3 Posters 0 Views 1 Watching
  • 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.
  • A Offline
    A Offline
    ajmalsiddiqi
    wrote on last edited by
    #1

    My application has several MFC threads running concurrently; these threads process their messages by using Peek Message. I want to know queue size in each thread (i.e. pending messages in thread queue).Is there any API that can tell me the message count or pending message count for each thread.? If there is no such an API, Is there any method to get message count at process level.?

    ajmalsiddiqui

    D S 2 Replies Last reply
    0
    • A ajmalsiddiqi

      My application has several MFC threads running concurrently; these threads process their messages by using Peek Message. I want to know queue size in each thread (i.e. pending messages in thread queue).Is there any API that can tell me the message count or pending message count for each thread.? If there is no such an API, Is there any method to get message count at process level.?

      ajmalsiddiqui

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Would GetQueueStatus() help?

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "Man who follows car will be exhausted." - Confucius

      A 1 Reply Last reply
      0
      • D David Crow

        Would GetQueueStatus() help?

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "Man who follows car will be exhausted." - Confucius

        A Offline
        A Offline
        ajmalsiddiqi
        wrote on last edited by
        #3

        Thanks for the response , but i think this would not because this function returns the type of messages in the queue, not message count or queue length. I wan to get number of messages in queue or number of pending messages in queue.

        ajmalsiddiqui

        D 1 Reply Last reply
        0
        • A ajmalsiddiqi

          Thanks for the response , but i think this would not because this function returns the type of messages in the queue, not message count or queue length. I wan to get number of messages in queue or number of pending messages in queue.

          ajmalsiddiqui

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          ajmalsiddiqi wrote:

          Thanks for the response , but i think this would not because this function returns the type of messages in the queue, not message count or queue length.

          It returns the number of the type you request.

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "Man who follows car will be exhausted." - Confucius

          1 Reply Last reply
          0
          • A ajmalsiddiqi

            My application has several MFC threads running concurrently; these threads process their messages by using Peek Message. I want to know queue size in each thread (i.e. pending messages in thread queue).Is there any API that can tell me the message count or pending message count for each thread.? If there is no such an API, Is there any method to get message count at process level.?

            ajmalsiddiqui

            S Offline
            S Offline
            Stephen Hewitt
            wrote on last edited by
            #5

            As far as I know you shouldn't run into any problems because the queue is too small. It's one of those questions that the very fact it's asked makes me wonder if your design is "correct". Can I ask why you need to know?

            Steve

            A 1 Reply Last reply
            0
            • S Stephen Hewitt

              As far as I know you shouldn't run into any problems because the queue is too small. It's one of those questions that the very fact it's asked makes me wonder if your design is "correct". Can I ask why you need to know?

              Steve

              A Offline
              A Offline
              ajmalsiddiqi
              wrote on last edited by
              #6

              Thanks, I am little bit cofused by your reply and unable to understand.There is no issue I just want to add some functionality in my application threads, I just want to check queue length,In my application there are 15 threads one of them is main thread(Controller Thread).All threads are posting theire different customized message and some data in WPARAM/LPARAM using using PostThreadMessage function. Now the controller thread receive all these messages using PeekMessage(pmsg, NULL, 0, 0, PM_NOREMOVE)from thread mesage queue in its Run method. // code snap shot Controller::Run() { While(1) { while(PeekMessage(pmsg, NULL, 0, 0, PM_NOREMOVE)) { switch(pmsg ->message) { case MSG_RE_START: // log here pending messages in queue //do some functionality case MSG_RE_StOP: // log here pending messages in queue //do some functionality } PeekMessage(pmsg, NULL, 0, 0, PM_REMOVE); } } } So when I receive one message I wan to log the pending messages which are still in queue and will be processed in next iteration means in call of PeekMessage. After Processing one Message I remove it from Thread queue using PeekMessage(pmsg, NULL, 0, 0, PM_REMOVE) So can I get the queue status , how many number of messages are in thread queue or queue length.?

              ajmalsiddiqui

              S 1 Reply Last reply
              0
              • A ajmalsiddiqi

                Thanks, I am little bit cofused by your reply and unable to understand.There is no issue I just want to add some functionality in my application threads, I just want to check queue length,In my application there are 15 threads one of them is main thread(Controller Thread).All threads are posting theire different customized message and some data in WPARAM/LPARAM using using PostThreadMessage function. Now the controller thread receive all these messages using PeekMessage(pmsg, NULL, 0, 0, PM_NOREMOVE)from thread mesage queue in its Run method. // code snap shot Controller::Run() { While(1) { while(PeekMessage(pmsg, NULL, 0, 0, PM_NOREMOVE)) { switch(pmsg ->message) { case MSG_RE_START: // log here pending messages in queue //do some functionality case MSG_RE_StOP: // log here pending messages in queue //do some functionality } PeekMessage(pmsg, NULL, 0, 0, PM_REMOVE); } } } So when I receive one message I wan to log the pending messages which are still in queue and will be processed in next iteration means in call of PeekMessage. After Processing one Message I remove it from Thread queue using PeekMessage(pmsg, NULL, 0, 0, PM_REMOVE) So can I get the queue status , how many number of messages are in thread queue or queue length.?

                ajmalsiddiqui

                S Offline
                S Offline
                Stephen Hewitt
                wrote on last edited by
                #7

                There are a number of issues here.   The first problem you may encounter is related to the posting of thread messages. Does the main thread have any UI? Messages boxes, dialogs, anything like that? If so you may encounter the problem described here[^]. The solution (posting the messages to a hidden window instead) is also described.   The next problem is that the main thread will sometimes throw away messages:

                // code snap shot
                Controller::Run()
                {
                While(1)
                {
                while(PeekMessage(pmsg, NULL, 0, 0, PM_NOREMOVE)) // -(1)
                {
                switch(pmsg ->message)
                {
                case MSG_RE_START:
                // log here pending messages in queue
                //do some functionality
                case MSG_RE_StOP:
                // log here pending messages in queue
                //do some functionality
                }
                }

                	PeekMessage(pmsg, NULL, 0, 0, PM\_REMOVE); // -(2)
                }
                

                }

                If there are no messages in the queue at point (1) but there is at point (2) the message is simply discarded. Another issue is that the main thread is constantly spinning in a busy loop doing nothing, degrading system performance. Also you simply discard all messages, even ones that don't belong to you. You should dispatch them. Also, even if your code was even close to working (which it's not) how do you know all the messages in the queue are yours?

                Steve

                A 1 Reply Last reply
                0
                • S Stephen Hewitt

                  There are a number of issues here.   The first problem you may encounter is related to the posting of thread messages. Does the main thread have any UI? Messages boxes, dialogs, anything like that? If so you may encounter the problem described here[^]. The solution (posting the messages to a hidden window instead) is also described.   The next problem is that the main thread will sometimes throw away messages:

                  // code snap shot
                  Controller::Run()
                  {
                  While(1)
                  {
                  while(PeekMessage(pmsg, NULL, 0, 0, PM_NOREMOVE)) // -(1)
                  {
                  switch(pmsg ->message)
                  {
                  case MSG_RE_START:
                  // log here pending messages in queue
                  //do some functionality
                  case MSG_RE_StOP:
                  // log here pending messages in queue
                  //do some functionality
                  }
                  }

                  	PeekMessage(pmsg, NULL, 0, 0, PM\_REMOVE); // -(2)
                  }
                  

                  }

                  If there are no messages in the queue at point (1) but there is at point (2) the message is simply discarded. Another issue is that the main thread is constantly spinning in a busy loop doing nothing, degrading system performance. Also you simply discard all messages, even ones that don't belong to you. You should dispatch them. Also, even if your code was even close to working (which it's not) how do you know all the messages in the queue are yours?

                  Steve

                  A Offline
                  A Offline
                  ajmalsiddiqi
                  wrote on last edited by
                  #8

                  There is no UI thread all are worker threads.This was not the exact code , the exact code is running well there is no issue in the application.I just write the scenrio of my requirment. 1.If there is message in the queue it will be processed and then will be removed.So there is need little correction is code: PeekMessage(pmsg, NULL, 0, 0, PM_REMOVE); // -(2) is inside the switch, not out of the inner while loop.

                  while(PeekMessage(pmsg, NULL, 0, 0, PM_NOREMOVE)) // -(1)
                  {
                  switch(pmsg ->message)
                  {
                  case MSG_RE_START:
                  // log here pending messages in queue
                  //do some functionality
                  break;
                  case MSG_RE_STOP:
                  // log here pending messages in queue
                  //do some functionality
                  break;
                  case MSG_RE_DATA:
                  // get number of pending messages
                  //Process data
                  break;

                  		}
                  

                  PeekMessage(pmsg, NULL, 0, 0, PM_REMOVE); // -(2)
                  }

                  2.The main thread is not constantly spinning in a busy loop, becasue it waits on some events when exits from the inner loop.I did not mention, So leave it 3. Leave this, assume that the application is running not closing. I just want to know that How can i get the pending number of messages in queue , for example when i receive MSG_RE_DATA message,How many number of messages MSG_RE_DATA are pending.

                  ajmalsiddiqui

                  S 1 Reply Last reply
                  0
                  • A ajmalsiddiqi

                    There is no UI thread all are worker threads.This was not the exact code , the exact code is running well there is no issue in the application.I just write the scenrio of my requirment. 1.If there is message in the queue it will be processed and then will be removed.So there is need little correction is code: PeekMessage(pmsg, NULL, 0, 0, PM_REMOVE); // -(2) is inside the switch, not out of the inner while loop.

                    while(PeekMessage(pmsg, NULL, 0, 0, PM_NOREMOVE)) // -(1)
                    {
                    switch(pmsg ->message)
                    {
                    case MSG_RE_START:
                    // log here pending messages in queue
                    //do some functionality
                    break;
                    case MSG_RE_STOP:
                    // log here pending messages in queue
                    //do some functionality
                    break;
                    case MSG_RE_DATA:
                    // get number of pending messages
                    //Process data
                    break;

                    		}
                    

                    PeekMessage(pmsg, NULL, 0, 0, PM_REMOVE); // -(2)
                    }

                    2.The main thread is not constantly spinning in a busy loop, becasue it waits on some events when exits from the inner loop.I did not mention, So leave it 3. Leave this, assume that the application is running not closing. I just want to know that How can i get the pending number of messages in queue , for example when i receive MSG_RE_DATA message,How many number of messages MSG_RE_DATA are pending.

                    ajmalsiddiqui

                    S Offline
                    S Offline
                    Stephen Hewitt
                    wrote on last edited by
                    #9

                    ajmalsiddiqi wrote:

                    while(PeekMessage(pmsg, NULL, 0, 0, PM_NOREMOVE)) // -(1) { switch(pmsg ->message) { case MSG_RE_START: // log here pending messages in queue //do some functionality break; case MSG_RE_STOP: // log here pending messages in queue //do some functionality break; case MSG_RE_DATA: // get number of pending messages //Process data break; } PeekMessage(pmsg, NULL, 0, 0, PM_REMOVE); // -(2) }

                    In this code the PeekMessage is not "inside the switch", it's in the while. Match up the brackets in the code you posted.

                    Steve

                    A 1 Reply Last reply
                    0
                    • S Stephen Hewitt

                      ajmalsiddiqi wrote:

                      while(PeekMessage(pmsg, NULL, 0, 0, PM_NOREMOVE)) // -(1) { switch(pmsg ->message) { case MSG_RE_START: // log here pending messages in queue //do some functionality break; case MSG_RE_STOP: // log here pending messages in queue //do some functionality break; case MSG_RE_DATA: // get number of pending messages //Process data break; } PeekMessage(pmsg, NULL, 0, 0, PM_REMOVE); // -(2) }

                      In this code the PeekMessage is not "inside the switch", it's in the while. Match up the brackets in the code you posted.

                      Steve

                      A Offline
                      A Offline
                      ajmalsiddiqi
                      wrote on last edited by
                      #10

                      it must be inside the inner loop and out of the switch.

                      ajmalsiddiqui

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups