CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2001
    Posts
    143

    Multithreading without MFC

    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

  2. #2
    Join Date
    May 2000
    Location
    Phoenix, AZ [USA]
    Posts
    1,347

    Re: Multithreading without MFC

    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.


  3. #3
    Join Date
    May 2002
    Location
    Atlanta,GA
    Posts
    262

    Re: Multithreading without MFC

    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
    Jared

  4. #4
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470

    Re: Multithreading without MFC

    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
    Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
    --
    Sutter and Alexandrescu, C++ Coding Standards

    Programs must be written for people to read, and only incidentally for machines to execute.

    --
    Harold Abelson and Gerald Jay Sussman

    The cheapest, fastest and most reliable components of a computer system are those that aren't there.
    -- Gordon Bell


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured