15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Multithreading and MFC internet classes

Jim McCabe -- jmccabe@mail.portup.com
Wednesday, September 04, 1996

Environment: Win95, MSVC 4.2a, IE 3.0

I've got a program that will connect to a web site using the new MFC internet
classes, and I'd like to use multithreading to speed things up a bit.  My
network stuff can be divided into chunks that can work in parallel, and I'd
like to have the threads organized as follows:

1:   Main application thread, processes UI
2:   Network management thread, controlling network activity
3-8: About five subordinate threads, which:
     a) post form data to a web server, using CHttpConnection::OpenRequest()
     b) obtain the response data, using CHttpFile::Read()
     c) process the response
     d) communicate the results back to the parent thread (2)
        using CWinThread::PostThreadMessage() or some kind of synchronization
        object

My specific question:  does each subordinate thread (3-8) need to establish an
entirely new connection to the web server, or can the CInternetSession and
CInternetConnection objects from thread 2 be shared by them?  That is, if
thread 2 creates a CHttpConnection object, is it safe to pass a pointer to
that object to the subordinate threads, and let them independently call
OpenRequest?

My first hunch was that the MFC net classes would operate like the other
handle-wrapper classes (CWnd, etc), preventing shared use among different
threads.  However, I haven't seen anything in the documentation warning
against this with the internet classes, and the wininet docs suggest that the
Win32 API are able to support my design.  (See the documentation under
"Microsoft ActiveX SDK" - "Microsoft Win32 Internet Programmers Reference" -
"Overview of the Win32 Internet Functions" - "Multithreaded Access".  Also see
the overview sheet in that same book.)



Mike Blaszczak -- mikeblas@nwlink.com
Friday, September 06, 1996

At 12:29 PM 9/4/96 -0400, you wrote:

>My specific question:  does each subordinate thread (3-8) need to establish an
>entirely new connection to the web server, or can the CInternetSession and
>CInternetConnection objects from thread 2 be shared by them? 

According to the documentation, WININET functions are completely reentrant
and thread-safe.

.B ekiM
http://www.nwlink.com/~mikeblas/
These words are my own. I do not speak on behalf of Microsoft.





| Вернуться в корень Архива |