Search code examples
multithreadingincludepthreadsheader-filesborland-c++

Multi threading in borland


I'm programming c++ in Borland c++ 5.02. I'm trying to run this code:

#include <stdio.h>
#include <pthread.h>

#define NUM 5

main()
{
  pthread_t t1, t2; /* two threads */

  void *print_msg(void *);

  pthread_create(&t1, NULL, print_msg, (void *)"hello");
  pthread_create(&t2, NULL, print_msg, (void *)"world\n");
  pthread_join(t1, NULL);
  pthread_join(t2, NULL);
}

But I get this error:

Info :Compiling C:\BC5\BIN\noname00.cpp

Error: noname00.cpp(2,2):Unable to open include file 'PTHREAD.H'

Error: noname00.cpp(8,15):Undefined symbol 'pthread_t'

Error: noname00.cpp(8,15):Statement missing ;

Error: noname00.cpp(12,18):Call to undefined function 'pthread_create'

I highlighted the main error which is caused by 'PTHREAD.H'. I checked the include folder for this file. It doesn't exist. How can I fix this problem?


Solution

  • Borland's C++ toolchain doesn't include a pthreads library, nor does the Windows SDK. You'll either need to use native Win32 thread APIs or get a 3rd party pthreads implementation for Windows.

    Some options include:

    I have no idea how well those things work with Borland C++ 5.x.

    Another alternative is to use a toolchain that includes a pthreads implementation, such as TDM's MinGW toolchain: