Creating Threads - Compilation error

This is a discussion on Creating Threads - Compilation error within the C Programming forums, part of the General Programming Boards category; Hi, I am trying to compile this standard example program from Borland C++ but i am getting error _beginthread() and ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    9

    Unhappy Creating Threads - Compilation error

    Hi,

    I am trying to compile this standard example program from Borland C++ but i am getting error _beginthread() and _exitthread() undeclared identifier. I am not able to figure out why? I suppose some change in runtime options settings is reqd . Please help. i am appending the code below.
    __________________________________________________ __



    #include <stdio.h>
    #include <errno.h>
    #include <stddef.h> /* _threadid variable */
    #include <process.h> /* _beginthread, _endthread */
    #include <time.h> /* time, _ctime */



    //#pragma comment(lib,"crtldll.lib")
    void thread_code(void *threadno)
    {
    time_t t;

    time(&t);
    printf("Executing thread number %d, ID = %d, time = %s\n",
    (int)threadno, _threadid, ctime(&t));
    _endthread();
    }

    void start_thread(int i)
    {
    int thread_id;

    #if defined(__WIN32__)

    if ((thread_id = _beginthread(thread_code,4096,(void *)i)) == (unsigned long)-1)
    #else
    if ((thread_id = _beginthread(thread_code,4096,(void *)i)) == -1)
    #endif
    {
    printf("Unable to create thread %d, errno = %d\n",i,errno);
    return;
    }
    printf("Created thread %d, ID = %ld\n",i,thread_id);
    }

    int main(void)
    {
    int i;

    for (i = 1; i < 20; i++)
    start_thread(i);
    printf("Hit ENTER to exit main thread.\n");
    getchar();

    return 0;
    }

    __________________________________________________ __


    Ashu

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    With VC++, tou need to set the compiler options to read from the threadsafe libraries...but with Borland I dont know......

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    9
    Please, Tell me settings for VC++ environment




    Ashu

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Originally posted by ashu12
    Please, Tell me settings for VC++ environment




    Ashu
    For VC++6

    Project->Settings->C++->Category->Code Generation->Use Runtime Library

    Setit to what you want from there

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 03:09 AM
  2. How to monitor process creation?
    By markiz in forum Windows Programming
    Replies: 31
    Last Post: 03-17-2008, 02:39 PM
  3. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  4. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 06:33 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM

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