i'm making my own input using the richedit win32 class.
for that i must use a structure for not lose the variable adress...
Code:
struct arg_readmultithread
    {
        consolewindow *consolewindowpointer=NULL;
        string *strreaded=NULL;
        char *chrreaded=NULL;
        double *dblreaded=NULL;
        string txtwrite="";
    };

    arg_readmultithread arg_multiread;


    void APIDoEvents()
    {
        MSG msg;
        BOOL result;
        while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE )|| blnread==true)
        {
            if(blnread==false)
                break;
            TranslateMessage(&msg);
            if(blnread==false)
                break;
            DispatchMessage(&msg);
            if(blnread==false)
                break;
        }
    }

    pthread_t some_thread;
    pthread_mutex_t myMutex=PTHREAD_MUTEX_INITIALIZER;
    pthread_cond_t  condition_var   = PTHREAD_COND_INITIALIZER;

    void multi_read(char *chr, string *str, double *dbl)
    {
        pthread_mutex_lock(&myMutex);
        /*while(blnread==true)
        {
            if(GetInputState()==TRUE && (GetKeyState(VK_RETURN) & 0x8000) && (blnread==false))
            {
                break;
            }
        }*/

        blnread=true;

        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);//getting the actual variable adress(debuging the code)

    }

    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
    }



    void read(string &txttext)
    {
        //change edit control seltext color:
        CHARFORMAT2 cf ;
        cf.cbSize = sizeof( CHARFORMAT2 ) ;
        cf.dwMask = CFM_COLOR | CFM_BACKCOLOR | CFM_EFFECTS2 ;
        cf.crTextColor =clrTextColor;
        cf.dwEffects =0;
        cf.crBackColor = clrTextBackColor;
        SendMessage(consoleedit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf );

        //recive the variable adress:
        arg_multiread.consolewindowpointer=this;
        arg_multiread.strreaded=&txttext;

        //create a new thread:
        pthread_create(&some_thread, nullptr, &consolewindow::multithreadproc,static_cast<void*>(&arg_multiread));
    }
when the return key is pressed the thread will be closed:
Code:
case WM_KEYUP:
            {
                if((wParam==VK_RETURN) && (richedit->blnread==true))
                {
                    if((is_number(richedit->readstring)==true))
                        if(richedit->dblreaded!=NULL)
                            *richedit->dblreaded=stod(richedit->readstring);
                    else
                    {
                        *richedit->dblreaded=0;

                    }
                    if(richedit->strreaded!=NULL)
                        *richedit->strreaded=richedit->readstring;
                    richedit->readstring="";
                    //richedit->strreaded=NULL;
                    richedit->blnread=false;
                    pthread_mutex_unlock(&richedit->myMutex);


                    //pthread_cond_signal( &richedit->condition_var );

                }
            }
            break;
the multithread is, sometimes... i repeat... sometimes, working correctly. but other times i lose the correct variable adress
can anyone tell me what i'm doing wrong with the multithread synchronization?
i had read several tutorials, but i continue with same problems.... 90% of code, works fine... but not always