1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
struct arg_readmultithread
{
consolewindow *consolewindowpointer=NULL;
string *strreaded=NULL;
char *chrreaded=NULL;
double *dblreaded=NULL;
};
arg_readmultithread arg_multiread;
void APIDoEvents()
{
MSG msg;
BOOL result;
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE ))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
HANDLE ghWriteEvent{CreateEvent(
NULL, // default security attributes
TRUE, // manual-reset event
FALSE, // initial state is nonsignaled
TEXT("WriteEvent") // object name
)};
void multi_read(char *chr, string *str, double *dbl)
{
if(blnread==true)
{
while(blnread==true)
{
APIDoEvents();
//WaitForSingleObject( hIOMutex, INFINITE );
}
}
SetEvent(ghWriteEvent);
blnread=true;
//WaitForSingleObject( hIOMutex, INFINITE );
strreaded=str;
//dblreaded=dbl;
ostringstream address;
address << strreaded;
std:string name = address.str();
static int i=0;
i=i+1;
DebugText("on function" + to_string(i) + ": "+ name);
WaitForSingleObject(ghWriteEvent, INFINITE);
}
static void *multithreadproc(void *pThisArg)
{
arg_readmultithread *pThis = static_cast<arg_readmultithread*>(pThisArg);
pThis->consolewindowpointer->multi_read(NULL,pThis->strreaded,pThis->dblreaded);
return nullptr;//terminates the thread
}
pthread_t some_thread;
void read(string &txttext)
{
delay(100);
arg_multiread.consolewindowpointer=this;
arg_multiread.strreaded=&txttext;
pthread_create(&some_thread, nullptr, consolewindow::multithreadproc,static_cast<void*>(&arg_multiread));
}
|