qt-interest@trolltech.com
[Top] [All Lists]

Re: GUI thread

Subject: Re: GUI thread
From: tj
Date: Mon, 31 Jan 2005 17:50:10 -0500
Hendrik Greving wrote:

I describe my problem more in general, asking such narrow question is often a bad idea, maybe somebody has the brilliant idea.

I have a function set that will be accessed from the gui as well as from another thread. These function must return a status code. Well, my first idea was to post an event and then to block the calling thread with a semaphore, what has been discussed here and everywhere a thousand times. But this idea sucks if the calling thread is the gui. This thread will block itself and everything stucks. I tried workarounds by calling sendevent afterwards, but sometimes tihs doesn't work either, maybe the event queue is accumulated by Qt, I don't know.

So the only possibility that I see for this is to know what thread is calling, and to block the call for a different (than the GUI~) thread, and to call directly (without postevent...) for the GUI thread.

Unfortunately my API gives me no information about what thread is calling. That may be sloppy implementation but I rely on that grubby API.

Hendrik


Hendrik Greving wrote:

Hello,

can I determine by some global thread ID or s.th. else if I am currently in the GUI thread?

cheers,
Hendrik


--
List archive and information: http://lists.trolltech.com/qt-interest/

I, for one, am confused. You seem to state the you have a function that is called by different threads, but no mention as to whether your function is thread safe. If it is not thread safe it must be protected, mutex, enter/leave critical secton, etc so no more then one thread can run it at a time. If it is not thread safe and not protected, then different threads accessing it at the same time can cause all sorts of trouble. Your comment "but sometimes this doesn't work either," emphasis on "sometimes" leads me to believe that multiple threads are calling a non-thread safe function.

If my interpretation is wrong, I apologize and disregard the above :-).

tj

--
List archive and information: http://lists.trolltech.com/qt-interest/

<Prev in Thread] Current Thread [Next in Thread>