Thread: threads

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    155

    threads

    how is concurrent programming accomplished in c++,the compiler starts complaining when i use _beginthread().

    compiler: dmc
    os: windows xp

  2. #2
    Just kidding.... fnoyan's Avatar
    Join Date
    Jun 2003
    Location
    Still in the egg
    Posts
    275
    Hi

    You can use Win32 CreateThread() system call. This allows you to get more control on your thread. Also, MSDN website includes detailed information about multithreaded programming under Win32 environment.

    You may want to check the address below
    http://msdn.microsoft.com/library/de...ing_Topics.asp

  3. #3
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    Read the compiler documentions.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  4. #4
    Registered User
    Join Date
    Feb 2006
    Posts
    155
    why doesnt c++ support threads?
    and is the _beginthread() function of the c langauge compiler specific or is it a standard.

    i was lookin for information about multithreading with c++,
    i came across posix threads,i dont know much about them,and my compiler doesnt include the pthread.h anyway even though it is right there in its include folder,who knows why.
    i suppose u cant include pthread in a windows environment?


    and i also came across some literature on how to have a thread wrapper class,is it required?,this is not java anyway.

    and i am lookin for a non mfc way of working with threads.

  5. #5
    Just kidding.... fnoyan's Avatar
    Join Date
    Jun 2003
    Location
    Still in the egg
    Posts
    275
    Well, MS provides you a MFC interface for Win32 C++, but you say you don't want, why?

    >why doesnt c++ support threads?
    If you use C++ you can still use Win32 C API! C also does not support in standarts. You have to emplay additional libraries in order to use threads.

    Did you try google to see whether or not POSIX threads (pthread) can be used under Windows!?

    The first link from goole

    http://sourceware.org/pthreads-win32/

  6. #6
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    I think threading is the duty of OS, not the compiler.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  7. #7
    Just kidding.... fnoyan's Avatar
    Join Date
    Jun 2003
    Location
    Still in the egg
    Posts
    275
    >I think threading is the duty of OS, not the compiler.
    The compiler also can do threading. Actually Linux is not full multithreaded system. When you create a process there is only only one main thread running in it. Still, (I am not sure) the thread support is not a part of kernel. It is implemented by using pthread library.

    You can also write your own thread library, but it requires deep knowledge of process management (Scheduling, etc...).

    On the other hand, Windows has CreateThread() system call which enables you to create a thread inside of a process (prorbably created with CreateProcess()).

  8. #8
    Registered User
    Join Date
    Feb 2006
    Posts
    155
    > Well, MS provides you a MFC interface for Win32 C++, but you say you don't want, why?

    well that introduces platform dependencies,the code is not portable,what if i dont have access to a windows system and i have to use linux,do i have to rewrite the whole thing?
    or i have to download special translation libraries?

  9. #9
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    Use precompiler conditioning.
    I learned aimple multi threading yesterday from adrianxw tutorial. Include process.h and use _beginthread() to call a function as a new thread. I don't know linux but I think when there is no portable code, you should use precompiler conditioning like this:
    Code:
    #define LINUX //Change it whenever you want.
    #if defined LINUX
    //LINUX calls
    #elif defined WINDOWS
    //Windows calls
    #endif
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  10. #10
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    use boost.threads. it's a portable threading system written by some of the best C++experts around.
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  11. #11
    Just kidding.... fnoyan's Avatar
    Join Date
    Jun 2003
    Location
    Still in the egg
    Posts
    275
    If you care about portablity just visit the link a posted. Any popular UNIX system support POSIX threads and you can use pthread under Windows. If you want, you can statically link the libraries under windows.

  12. #12
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    boost.threads uses the native threading system on each platform and is likely to become the standard c++ threading interface. It's a fully realised object oriented interface, why wouldn't you use that over pthread, (which IIRC, is a c interface)?

    http://www.boost.org/libs/thread/doc/index.html
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 10-17-2008, 11:28 AM
  2. Yet another n00b in pthreads ...
    By dimis in forum C++ Programming
    Replies: 14
    Last Post: 04-07-2008, 12:43 AM
  3. Classes and Threads
    By Halloko in forum Windows Programming
    Replies: 9
    Last Post: 10-23-2005, 05:27 AM
  4. problem with win32 threads
    By pdmarshall in forum C++ Programming
    Replies: 6
    Last Post: 07-29-2004, 02:39 PM
  5. Block and wake up certain threads
    By Spark in forum C Programming
    Replies: 9
    Last Post: 06-01-2002, 03:39 AM