Babak.Abad
Babak.Abad

Reputation: 2956

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?

Upvotes: 0

Views: 1590

Answers (2)

Michael Burr
Michael Burr

Reputation: 340218

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:

Upvotes: 2

Spektre
Spektre

Reputation: 51845

your problem is #include <pthread.h>

  • you need either copy all the pthread related files (.h,.c,.cpp,.hpp,.lib,.obj)
  • into compiler include folder
  • or add include path to it in your project/compiler settings
  • or copy it locally to your project and change #include <pthread.h> to #include "pthread.h"

So compiler did not find the pthread.h header

  • so no datatype from it is known from compiler side (like pthread_t)
  • therefore the rest of the errors...

Upvotes: 0

Related Questions