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