Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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: 13975
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: Sat Apr 20 13:07:35 CEST 2024

Total time taken to generate the page: 0.13389 seconds