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 |
|
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
|
|
|
Goto Forum:
Current Time: Sat Apr 20 13:07:35 CEST 2024
Total time taken to generate the page: 0.13389 seconds
|