how can i create a new thread by order?
1 - the new thread is created;
2 - test if we are on thread, then we wait until the return key is pressed;
3 - else enter on new thread.

i have my own read() method:
Code:
struct arg_readmultithread
    {
        consolewindow *consolewindowpointer=NULL;
        string *strreaded=NULL;
        char *chrreaded=NULL;
        double *dblreaded=NULL;
    };

    arg_readmultithread arg_multiread;
    HANDLE    hIOMutex;

    void APIDoEvents()
    {
        MSG msg;
        BOOL result;
        while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE ))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    pthread_t some_thread;
    pthread_mutex_t myMutex;

    void multi_read(char *chr, string *str, double *dbl)
    {

        if(blnread==true)
        {
             while(blnread==true)
            {
                APIDoEvents();
                //WaitForSingleObject( hIOMutex, INFINITE );
            }
        }
        blnread=true;
        //pthread_mutex_lock(&myMutex);
        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);

    }

    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)
    {
        arg_multiread.consolewindowpointer=this;
        arg_multiread.strreaded=&txttext;
        pthread_create(&some_thread, nullptr, &consolewindow::multithreadproc,static_cast<void*>(&arg_multiread));
    }
//on richedit window procedure:
Code:
static LRESULT APIENTRY RichEditProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
    {
        consolewindow *richedit = (consolewindow *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);


        switch(uMsg)
        {
            case WM_SIZE:
            {
                while(1)
                {
                    richedit->APIDoEvents();
                    ::CreateCaret(hwndDlg, NULL, 1, 0);//the size it's on pixels
                    ::SetCaretPos(0, 1);//wrong position... i get on pixel y=1 or zero.
                    ::ShowCaret(hwndDlg);//showed
                }
            }
            break;
            case WM_KEYDOWN:
            {
                if((wParam==VK_RETURN) && (richedit->blnread==true))
                {
                    //pthread_mutex_unlock(&richedit->myMutex);

                    richedit->blnread=false;
                    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="";

                }
                else if((wParam==VK_BACK) && (richedit->blnread==true))
                {
                    if(richedit->readstring.size()>=1)
                        richedit->readstring.pop_back();
                    else
                        return 0;
                }
            }
            break;
my problem is these output:
Code:
before read: 0x28fb00
before read2: 0x28faf8
before read3: 0x28faf4
on function1: 0x28faf8
like you see 'function1' is '0x28faf8' instead '0x28fb00'. i had tryied the mutex code for synchronization and the win32 event functions, without sucess
the APIDoEvents() loop is for the window continue been responding to events.
what you can advice me?