Call to undefined function '_beginthreadex' in function main() - C (СИ)
Формулировка задачи:
Здесь реализуется задача о 5-ти китайских философах, обедающих за столом
не запускается как консольное приложение в Borland, выдает вот эту ошибку:Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
1philos.cpp:
Error E2268 1philos.cpp 68: Call to undefined function '_beginthreadex' in function main()
*** 1 errors in Compile ***
помогите разобраться в чем дело, пожалуйста
#include<windows.h> //подключаем библиотеки
#include<stdlib.h>
#include<process.h>
#include<stdio.h>
#include<conio.h> //библиотека содержащая функцию очистки экрана
HANDLE hstdin, hstdout, hthread1, hthread2, hthread3, hthread4, hthread5, hthread6, hthread7, fork1, fork2, fork3, fork4, fork5, fork6, fork7; //хэндлы для работы нитей, семафоров вилок и ввода вывода
CRITICAL_SECTION csec; // критическая секция для работы с выводом на экран
void main() //основная программа
{
//обозначаем что нити будут расположены после основной части программы
void phil1();
void phil2();
void phil3();
void phil4();
void phil5();
void phil6();
void phil7();
unsigned long threadid1,threadid2,threadid3,threadid4,threadid5,threadid6,threadid7; //идентификатор для нитей
DWORD actlen,pmode; // параметры для установки опроса консоли
COORD pos; // координатная переменная
INPUT_RECORD inpbuf; // переменная принятия событий от консоли
int j; // переменная определяющая координату мышки по Y
InitializeCriticalSection(&csec); //инициализация критической секции для правильного согласования работы параллельных нитей
hstdout=GetStdHandle(STD_OUTPUT_HANDLE); // инициализация хэндлов ввода, ввывода
hstdin=GetStdHandle(STD_INPUT_HANDLE);
fork1=CreateMutex(NULL,FALSE,NULL); //инициализация семафоров Mutex для вилок
if (fork1==NULL)
{printf("Mutex=%d\n", fork1);
getchar();}
fork2=CreateMutex(NULL,FALSE,NULL);
if (fork2==NULL)
{printf("Mutex=%d\n", fork2);
getchar();}
fork3=CreateMutex(NULL,FALSE,NULL);
if (fork3==NULL)
{printf("Mutex=%d\n", fork3);
getchar();}
fork4=CreateMutex(NULL,FALSE,NULL);
if (fork4==NULL)
{printf("Mutex=%d\n", fork4);
getchar();}
fork5=CreateMutex(NULL,FALSE,NULL);
if (fork5==NULL)
{printf("Mutex=%d\n", fork5);
getchar();}
fork6=CreateMutex(NULL,FALSE,NULL);
if (fork6==NULL)
{printf("Mutex=%d\n", fork6);
getchar();}
fork7=CreateMutex(NULL,FALSE,NULL);
if (fork7==NULL)
{printf("Mutex=%d\n", fork7);
getchar();}
hthread1=(HANDLE)_beginthreadex(phil1, 4096, NULL, NULL, 0, &threadid1); //Запуск нитей
if(hthread1==NULL) {printf("hthread1=%d\n", hthread1); getchar();}
hthread2=(HANDLE)_beginthreadex(phil2, 4096, NULL, NULL, 0, &threadid2);
if(hthread2==NULL) {printf("hthread2=%d\n", hthread2); getchar();}
hthread3=(HANDLE)_beginthreadex(phil3, 4096, NULL, NULL, 0, &threadid3);
if(hthread3==NULL) {printf("hthread3=%d\n", hthread3); getchar();}
hthread4=(HANDLE)_beginthreadex(phil4, 4096, NULL, NULL, 0, &threadid4);
if(hthread4==NULL) {printf("hthread4=%d\n", hthread4); getchar();}
hthread5=(HANDLE)_beginthreadex(phil5, 4096, NULL, NULL, 0, &threadid5);
if(hthread5==NULL) {printf("hthread5=%d\n", hthread5); getchar();}
hthread6=(HANDLE)_beginthreadex(phil6, 4096, NULL, NULL, 0, &threadid6);
if(hthread6==NULL) {printf("hthread6=%d\n", hthread6); getchar();}
hthread7=(HANDLE)_beginthreadex(phil7, 4096, NULL, NULL, 0, &threadid7);
if(hthread7==NULL) {printf("hthread6=%d\n", hthread7); getchar();}
clrscr(); // очистка экрана
EnterCriticalSection(&csec); //вход в критическую секцию для запрета нитям использования
SetConsoleTextAttribute(hstdout,FOREGROUND_GREEN|FOREGROUND_RED); // установка цвета вывода
pos.X=0; //установка координат курсора вывода
pos.Y=0;
SetConsoleCursorPosition(hstdout,pos);
printf(" 00000 00000 00000 00000\n"); //рисование философов
printf(" 0* *0 0* *0 0* *0 0* *0\n");
printf(" 000 000 000 000 \n");
pos.X=0; //рисование вилок
pos.Y=4;
SetConsoleCursorPosition(hstdout,pos);
printf(" ---E ---E ---E ---E ---E\n");
pos.X=0;
pos.Y=7;
SetConsoleCursorPosition(hstdout,pos);
printf(" ---E ---E\n");
pos.X=0;
pos.Y=8;
SetConsoleCursorPosition(hstdout,pos);
printf(" 00000 00000 00000\n");
printf(" 0* *0 0* *0 0* *0\n");
printf(" 000 000 000 \n");
LeaveCriticalSection(&csec);
//инициализация работы с консолью
GetConsoleMode(hstdin,&pmode);
SetConsoleMode(hstdin,pmode | ENABLE_MOUSE_INPUT);
do //цикл основной программы до нажатия обоих клавиш мыши
{
ReadConsoleInput(hstdin,&inpbuf,1,&actlen); //чтение с консоли
if (inpbuf.Event.MouseEvent.dwButtonState==FROM_LEFT_1ST_BUTTON_PRESSED) //определение типа события консоли
{
j=inpbuf.Event.MouseEvent.dwMousePosition.X; //чтение координаты Y в переменную j
if ((j>=0)&(j<=14))
{ // затирка рук философов и освобождение семафоров вилок
EnterCriticalSection(&csec);
pos.X=5;
pos.Y=3;
SetConsoleCursorPosition(hstdout,pos);
printf(" ");
ReleaseMutex(fork1);
ReleaseMutex(fork2);
LeaveCriticalSection(&csec);
}
if ((j>=24)&(j<=30))
{
EnterCriticalSection(&csec);
pos.X=20;
pos.Y=3;
SetConsoleCursorPosition(hstdout,pos);
printf(" ");
ReleaseMutex(fork2);
ReleaseMutex(fork3);
LeaveCriticalSection(&csec);
}
if ((j>=41)&(j<=47))
{
EnterCriticalSection(&csec);
pos.X=35;
pos.Y=3;
SetConsoleCursorPosition(hstdout,pos);
printf(" ");
ReleaseMutex(fork3);
ReleaseMutex(fork4);
LeaveCriticalSection(&csec);
}
if ((j>=57)&(j<=63))
{
EnterCriticalSection(&csec);
pos.X=50;
pos.Y=3;
SetConsoleCursorPosition(hstdout,pos);
printf(" ");
ReleaseMutex(fork4);
ReleaseMutex(fork5);
LeaveCriticalSection(&csec);
}
if ((j>47)&(j<57))
{
EnterCriticalSection(&csec);
pos.X=47;
pos.Y=7;
SetConsoleCursorPosition(hstdout,pos);
printf(" ");
ReleaseMutex(fork5);
ReleaseMutex(fork6);
LeaveCriticalSection(&csec);
}
if ((j>30)&(j<41))
{
EnterCriticalSection(&csec);
pos.X=28;
pos.Y=7;
SetConsoleCursorPosition(hstdout,pos);
printf(" ");
ReleaseMutex(fork6);
ReleaseMutex(fork7);
LeaveCriticalSection(&csec);
}
if ((j>14)&(j<24))
{
EnterCriticalSection(&csec);
pos.X=10;
pos.Y=7;
SetConsoleCursorPosition(hstdout,pos);
printf(" ");
ReleaseMutex(fork1);
ReleaseMutex(fork7);
LeaveCriticalSection(&csec);
}
}
}
while (inpbuf.Event.MouseEvent.dwButtonState!=FROM_LEFT_1ST_BUTTON_PRESSED+RIGHTMOST_BUTTON_PRESSED);
DeleteCriticalSection(&csec); // завершение программы, закрытие хэндлов, удаление критической секции
CloseHandle(hthread1);
CloseHandle(hthread2);
CloseHandle(hthread3);
CloseHandle(hthread4);
CloseHandle(hthread5);
CloseHandle(hthread6);
CloseHandle(hthread7);
CloseHandle(hstdout);;
CloseHandle(fork1);
CloseHandle(fork2);
CloseHandle(fork3);
CloseHandle(fork4);
CloseHandle(fork5);
CloseHandle(fork6);
CloseHandle(fork7);
CloseHandle(hstdin);
}
// Нить философа1
void phil1()
{
COORD pos;
while(TRUE){
randomize(); // выполняется до завершения основной программы
Sleep(random(4800)); // случайное время прогулки философа
WaitForSingleObject(fork1, INFINITE); // ожидание освобождения вилки - семафора
WaitForSingleObject(fork2, INFINITE);
EnterCriticalSection(&csec); // отрисовка рук философа
SetConsoleTextAttribute(hstdout,FOREGROUND_BLUE);
pos.X=5;
pos.Y=3;
SetConsoleCursorPosition(hstdout,pos);
printf("M M");
LeaveCriticalSection(&csec);
Sleep(random(3000)); //случайное время состояния "ем"
pos.X=5; //затирка рук философа
pos.Y=3;
SetConsoleCursorPosition(hstdout,pos);
printf(" ");
ReleaseMutex(fork1); // освобождение вилок - семафоров
ReleaseMutex(fork2);
}
}
void phil2()
{
COORD pos;
while(TRUE){
randomize();
Sleep(random(5500));
WaitForSingleObject(fork2, INFINITE);
WaitForSingleObject(fork3, INFINITE);
EnterCriticalSection(&csec);
SetConsoleTextAttribute(hstdout,FOREGROUND_GREEN);
pos.X=20;
pos.Y=3;
SetConsoleCursorPosition(hstdout,pos);
printf("M M");
LeaveCriticalSection(&csec);
Sleep(random(2500));
pos.X=20;
pos.Y=3;
SetConsoleCursorPosition(hstdout,pos);
printf(" ");
ReleaseMutex(fork2);
ReleaseMutex(fork3);
}
}
void phil3()
{
COORD pos;
while(TRUE){
randomize();
Sleep(random(6000));
WaitForSingleObject(fork3, INFINITE);
WaitForSingleObject(fork4, INFINITE);
EnterCriticalSection(&csec);
SetConsoleTextAttribute(hstdout,FOREGROUND_BLUE);
pos.X=35;
pos.Y=3;
SetConsoleCursorPosition(hstdout,pos);
printf("M M");
LeaveCriticalSection(&csec);
Sleep(random(4000));
pos.X=35;
pos.Y=3;
SetConsoleCursorPosition(hstdout,pos);
printf(" ");
ReleaseMutex(fork3);
ReleaseMutex(fork4);
}
}
void phil4()
{
COORD pos;
while(TRUE){
randomize();
Sleep(random(3000));
WaitForSingleObject(fork4, INFINITE);
WaitForSingleObject(fork5, INFINITE);
EnterCriticalSection(&csec);
SetConsoleTextAttribute(hstdout,FOREGROUND_RED);
pos.X=50;
pos.Y=3;
SetConsoleCursorPosition(hstdout,pos);
printf("M M");
LeaveCriticalSection(&csec);
Sleep(random(5000));
pos.X=50;
pos.Y=3;
SetConsoleCursorPosition(hstdout,pos);
printf(" ");
ReleaseMutex(fork4);
ReleaseMutex(fork5);
}
}
void phil5()
{
COORD pos;
while(TRUE){
randomize();
Sleep(random(6000));
WaitForSingleObject(fork5, INFINITE);
WaitForSingleObject(fork6, INFINITE);
EnterCriticalSection(&csec);
SetConsoleTextAttribute(hstdout,FOREGROUND_GREEN);
pos.X=47;
pos.Y=7;
SetConsoleCursorPosition(hstdout,pos);
printf("M M");
LeaveCriticalSection(&csec);
Sleep(random(3000));
pos.X=47;
pos.Y=7;
SetConsoleCursorPosition(hstdout,pos);
printf(" ");
ReleaseMutex(fork5);
ReleaseMutex(fork6);
}
}
void phil6()
{
COORD pos;
while(TRUE){
randomize();
Sleep(random(5000));
WaitForSingleObject(fork6, INFINITE);
WaitForSingleObject(fork7, INFINITE);
EnterCriticalSection(&csec);
SetConsoleTextAttribute(hstdout,FOREGROUND_RED);
pos.X=28;
pos.Y=7;
SetConsoleCursorPosition(hstdout,pos);
printf("M M");
LeaveCriticalSection(&csec);
Sleep(random(3000));
pos.X=28;
pos.Y=7;
SetConsoleCursorPosition(hstdout,pos);
printf(" ");
ReleaseMutex(fork6);
ReleaseMutex(fork7);
}
}
void phil7()
{
COORD pos;
while(TRUE){
randomize();
Sleep(random(2000));
WaitForSingleObject(fork1, INFINITE);
WaitForSingleObject(fork7, INFINITE);
EnterCriticalSection(&csec);
SetConsoleTextAttribute(hstdout,FOREGROUND_RED|FOREGROUND_BLUE);
pos.X=10;
pos.Y=7;
SetConsoleCursorPosition(hstdout,pos);
printf("M M");
LeaveCriticalSection(&csec);
Sleep(random(4000));
pos.X=10;
pos.Y=7;
SetConsoleCursorPosition(hstdout,pos);
printf(" ");
ReleaseMutex(fork1);
ReleaseMutex(fork7);
}
}Решение задачи: «Call to undefined function '_beginthreadex' in function main()»
textual
Листинг программы
unsigned int threadid1,threadid2,threadid3,threadid4,threadid5,threadid6,threadid7; //идентификатор для нитей