c++windowsmultithreadingconsole-applicationborland-c++

Multi threading with 3rd party headerfiles in Borland C++ 5.02


Is there any header files or extension that I can use to make multi thread on Borland 5.02?

I want to make a program that animates two lines going in different speed, in an infinite loop. Something like this

#include <iostream.h>
#include <conio.h>
#include <windows.h>
#include<dos.h>


void linesmov(int seconds);

main()
{
// Thread 1
linesmov(5);

//Thread 2
linesmov(30);
}

void linesmov(int mseconds){

    int i=0;
while (true){
    i=i+1;
    clrscr();   // Or system("cls"); If you may...
    gotoxy(i,15);   cout << "____||____||____";
    Sleep(mseconds);
    if (i>115){     i=0;  }
}

}

Yes.. I know that people are going to go and say, GET A NEW COMPILER, My school uses old compiler as a "standard" on scoring, so please bear with me.


Solution

  • Hans Boehm wrote a famous paper on why that's a bad idea: Threads cannot be implemented as a library.

    In a nutshell, if you want to do multi-threaded programming, you need a language and a compiler that give certain guarantees with regards to thread-safety. If you do not have this, you will run into very weird and hard to understand bugs eventually.

    This was by the way one of the main reasons why thread support introduced with C++11 was such a big deal: Just using a library is not enough, you actually need proper support from the language as well.

    Since Borland C++ does not give these guarantees, do not expect it to carry you very far when using it for multi-threaded programming.