Click to See Complete Forum and Search --> : Multithreading without MFC
imi123_1999
May 15th, 2002, 08:37 AM
My team is given a task of developing a chat server. Ofcourse the server will be multithreaded.But the concern here is that we do not want to develop server using MFC. Reason is that we may want to deploy this server on LINUX platform in the future.
My question is that whether multithreading is possible using standard ANSI C++. Is there any method that we can develop the chat server in C++ using multithreading and can compile the same code in compilers like VC++ and on UNIX ???
ImI
PaulWendt
May 15th, 2002, 09:02 AM
Unfortunately, threading is not a part of C++. So, what are your options? Well, there are various releases of pthreads; I'm not totally sure if they compile on windows or not, but I know that they compile [at least on linux and I built them on hp-ux as well]. Here's the only link I have for the MIT pthreads, though you can find various other implementations on the net:
http://www.humanfactor.com/pthreads/mit-pthreads.html
Linux comes with pthreads, I think.
If they DON'T compile on WIN32, you'd have to encapsulate the two different thread-techniques in your own custom class so that your program had the same interface. There are packages out there that do this sort of thing; check out http://www.trolltech.com. QT is a commercial class library that supports cross-platform development, though it can be pricey. There are probably other cross-platform hierarchies out there as well.
jparsons
May 15th, 2002, 09:15 AM
I've run into this problem before. Here is how I tackled it. Create your own thread class. Inside this class write on Thread class for Windows using low level MFC threads, and one for Linux using Pthread. Wrap each class in an #ifdef. This class won't be pretty but it will give you the portability you want and save you a lot of headaches.
This isn't too difficult of a task. Low level Windows Threads have very similar function calls as do pthreads so The classes will be largely similar.
Jared Parsons
Graham
May 15th, 2002, 09:51 AM
I suggest you check out the boost library. This contains classes for multi threading and stands a good chance of being incorporated into the next C++ standard.
http://www.boost.org/libs/thread/doc/index.html
He who breaks a thing to find out what it is, has left the path of wisdom - Gandalf
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.