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. Completion Port and Multithreads :: MFC

Completion Port and Multithreads :: MFC

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++comsysadminperformance
4 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.
  • V Offline
    V Offline
    valikac
    wrote on last edited by
    #1

    Hi. I am working under an MFC environment. I would like to know, What is the performance difference, if any, resulting from the use of _beginthreadex and MFC's AfxBeginThread for an IOCP Winsock model client and server? I understand that for an MFC project, we should use MFC's AfxBeginThread to generate the threads. Nonetheless, does an IOCP client or server require or performs better via _beginthreadex? The reason I am wondering about this is that I saw some really good examples IOCP servers where the developers used _beginthreadex with MFC instead of AfxBeginThread(). Here is one example. http://www.codeproject.com/internet/winsockiocp.asp ----- A second question related to IOCP, _beginthreadex, and MFC's AfxBeginThread is the callback function. Under MFC's AfxBeginThread, you basically send/post messages from the worker thread the IOCP GetQueuedCompletionStatus() function returns. One the other hand, with _beginthreadex, you have the option of passing in a pointer to the class object itself (this). Thus, you can call a function to process incoming data directly without relying on send/post message. I would like to know, Is the analysis above true. In other words, does the use of send/post message via IOCP worker threads negatively affect performance? Thanks, Kuphryn

    R D 2 Replies Last reply
    0
    • V valikac

      Hi. I am working under an MFC environment. I would like to know, What is the performance difference, if any, resulting from the use of _beginthreadex and MFC's AfxBeginThread for an IOCP Winsock model client and server? I understand that for an MFC project, we should use MFC's AfxBeginThread to generate the threads. Nonetheless, does an IOCP client or server require or performs better via _beginthreadex? The reason I am wondering about this is that I saw some really good examples IOCP servers where the developers used _beginthreadex with MFC instead of AfxBeginThread(). Here is one example. http://www.codeproject.com/internet/winsockiocp.asp ----- A second question related to IOCP, _beginthreadex, and MFC's AfxBeginThread is the callback function. Under MFC's AfxBeginThread, you basically send/post messages from the worker thread the IOCP GetQueuedCompletionStatus() function returns. One the other hand, with _beginthreadex, you have the option of passing in a pointer to the class object itself (this). Thus, you can call a function to process incoming data directly without relying on send/post message. I would like to know, Is the analysis above true. In other words, does the use of send/post message via IOCP worker threads negatively affect performance? Thanks, Kuphryn

      R Offline
      R Offline
      rrrado
      wrote on last edited by
      #2

      Look into MFC sources, Afx... internally uses _begin.... i'd say, so performance will be the same


      rrrado

      1 Reply Last reply
      0
      • V valikac

        Hi. I am working under an MFC environment. I would like to know, What is the performance difference, if any, resulting from the use of _beginthreadex and MFC's AfxBeginThread for an IOCP Winsock model client and server? I understand that for an MFC project, we should use MFC's AfxBeginThread to generate the threads. Nonetheless, does an IOCP client or server require or performs better via _beginthreadex? The reason I am wondering about this is that I saw some really good examples IOCP servers where the developers used _beginthreadex with MFC instead of AfxBeginThread(). Here is one example. http://www.codeproject.com/internet/winsockiocp.asp ----- A second question related to IOCP, _beginthreadex, and MFC's AfxBeginThread is the callback function. Under MFC's AfxBeginThread, you basically send/post messages from the worker thread the IOCP GetQueuedCompletionStatus() function returns. One the other hand, with _beginthreadex, you have the option of passing in a pointer to the class object itself (this). Thus, you can call a function to process incoming data directly without relying on send/post message. I would like to know, Is the analysis above true. In other words, does the use of send/post message via IOCP worker threads negatively affect performance? Thanks, Kuphryn

        D Offline
        D Offline
        Daniel Lohmann
        wrote on last edited by
        #3

        AfxBeginThread() is just a small wrapper around _beginthreadex and does some extra MFC structure initialisations on thread creation and some cleanup on thread termination. If you are using the DLL version of MFC you don't have to care that much about it, because the same job is done in MFC42.dll's DllMain(). From the performance point of view both should be pretty the same. I usually prefer _beginthreadex() - just because you may decide one day to throw MFC away from your server app (which is not that unlikely, believe me :) ) -- Daniel Lohmann http://www.losoft.de (Hey, this page is worth looking! You can find some free and handy NT tools there :-D )

        V 1 Reply Last reply
        0
        • D Daniel Lohmann

          AfxBeginThread() is just a small wrapper around _beginthreadex and does some extra MFC structure initialisations on thread creation and some cleanup on thread termination. If you are using the DLL version of MFC you don't have to care that much about it, because the same job is done in MFC42.dll's DllMain(). From the performance point of view both should be pretty the same. I usually prefer _beginthreadex() - just because you may decide one day to throw MFC away from your server app (which is not that unlikely, believe me :) ) -- Daniel Lohmann http://www.losoft.de (Hey, this page is worth looking! You can find some free and handy NT tools there :-D )

          V Offline
          V Offline
          valikac
          wrote on last edited by
          #4

          Okay. Thanks. Excellent point on portability. Kuphryn

          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