Threads in C++

This is a discussion on Threads in C++ within the C++ Programming forums, part of the General Programming Boards category; Hey... Okay here's the deal. I'm thinking of creating an IRC client, but the thing is.. i don't know what ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    3

    Arrow Threads in C++

    Hey...
    Okay here's the deal. I'm thinking of creating an IRC client, but the thing is.. i don't know what to use or how to make it so that it's waiting for incoming messages from the server AND sending whatever i type in at the same time. Any input is appreciated.. thanks

    Regards
    rezonax


    ---
    CodePeople <-- if($needhelpwith=="programming") visit(codepeople);[

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    in response to the title,

    _beginthread
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    3

    Arrow Re: Threads in C++

    Thanks a bunch.. do you know where i can read up on that function?

    rezonax

  4. #4
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    if you have MSVC use the MSDN, borland builder has a library that has it.

    if you don't have those,

    unsigned long _beginthread( void( __cdecl *start_address )( void * ), unsigned stack_size, void *arglist );

    Paramaters:

    start_address

    Start address of routine that begins execution of new thread

    stack_size

    Stack size for new thread or 0

    arglist

    Argument list to be passed to new thread or NULL

    void _endthread(void)

    used to terminate the thread created by begin thread.

    use them like so

    Code:
    int counter = 0;
    
    // this functio must be declaread in this format void myfunc(void*)
    void ThreadFunc(void* v)
    {
       while(counter < 10000);
       _endthread(); // must be called to cleanup after thread
    }
    
    main()
    {
        bool done = false;
        // do not include the parentheses when passing the function to beginthread
        _beginthread(ThreadFunc,0,NULL);
        while(!done)
        {
            if(counter%1000)
                printf("Counter:%d",counter);
        }
        return 0;
    }
    this shuld print the value of counter ten times
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

Popular pages Recent additions subscribe to a feed

Similar Threads

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21