U++ framework
Do not panic. Ask here before giving up.

Home » U++ Library support » U++ MT-multithreading and servers » Thread calls GUI
Re: Thread calls GUI [message #20058 is a reply to message #20056] Sun, 15 February 2009 08:24 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 14291
Registered: November 2005
Ultimate Member
Unfortunately, Gate cannot work here. Gate is supposed to return the value, which is not possible until callback is performed..

I am afraid that the solution for your problem might be quite complex.

IMO, you will have to use something like Semaphore on thread part. Use PostCallback to signal to GUI thread you need that prompt, enter semaphore after PostCallback.

GUI thread then performs the prompt, signals the result via some shared variable, then releases semaphore of thread to get it going.

void DoAsk(Semaphore *sem, int *result)
{
   *result = PromptYesNo("");
   sem->Release();
}

struct MyThread {
    int Ask() {
        Sempahore sem;
        int result;
        PostCallback(callback2(DoAsk, &sem, &result));
        sem.Wait();
        return result;
    }
}


(To my best knowledge, we do not need mutex for result, as sempahore does the synchronization for us as well).

(Not testes, but should work).

Mirek
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: StaticMutex/ONCELOCK question
Next Topic: GUI MT project does not compile
Goto Forum:
  


Current Time: Fri Sep 18 05:38:18 GMT+2 2026

Total time taken to generate the page: 0.00727 seconds