Thread: Threads, .h-file, guide?

  1. #1
    Registered User
    Join Date
    May 2008

    Threads, .h-file, guide?

    // Hi, how do i make and use threads in windows?
    // is it possible to use linux posix threads? or would everything just crash?

    found some in msdn about process.h with _beginthreadex.
    anyone who have used this before that can explain a bit on how to use them or a guide..

    mostly need to know how to get diffrent threads to interact with eachother.

    trying to make a server that gives each new client a new thread and a socket.

    they shall later on be able to "chat"..

    any guides on the topic would be nice..
    Last edited by wixz64; 05-26-2008 at 04:42 AM.

  2. #2
    Registered User
    Join Date
    Apr 2008
    Windows is not, as far I know, posix-compliant so if you use the native API this won't be posix threads. However the interface seems quite similar so you won't see much difference (as long as you don't care how it's managed from the O/S viewpoint).

    Starting from here:

    You create a new thread with CreateThread():

    the principle is that you provide a function to this routine from where the new thread will start (the main-like function for the thread). Other parameters are the thread attributes (scheduling policy etc.) keep the default values for now.

    mostly need to know how to get diffrent threads to interact with eachother
    You have to do it yourself: your threads will share the same memory space (except for their stack). Global variables for instance, or dynamically allocated memory are accessible to all threads (be sure to add a synchronization mechanism). If those things are not familiar to you, try to read some general documentation/courses about multithreading programming, this is not so obvious and you must be sure to understand them first.
    A quick google search gives you plenty of references. Also try "win32 CreateThread" for code samples.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 07:54 AM
  3. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  4. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM