PDA

View Full Version : doubt in blocking fortune client example



wagmare
19th February 2009, 10:43
hi friends,
for learning threads i am going on the blockingfortune client ..
i am trying to find why they use cond.wakeOne()
can anybody please explain clearly of QWaitCondition() on blocking fortune client example ... the step i try to follow in assistant docs cant help me .. can u guide a little about it please .... :o
the main doubt is whn ever the user clicks getFortune a new thread will create ..?

talk2amulya
19th February 2009, 11:52
no, whenever the user clicks the button, the button gets disabled and the same thread would start or restart and wait for a new fortune to come and as soon as it comes, it will emit a newFortune() signal with the fortune string, which is then caught by the blocking client and shown

wagmare
19th February 2009, 12:03
thanks for the reply first ..
why we have to use this QWaitCondition ...
as
void QWaitCondition::wakeOne ()
Wakes one thread waiting on the wait condition. The thread that is woken up depends on the operating system's scheduling policies, and cannot be controlled or predicted.
If you want to wake up a specific thread, the solution is typically to use different wait conditions and have different threads wait on different condition.

talk2amulya
19th February 2009, 12:34
in this example, waitOne() is used to wake up Fortune Thread itself cuz that is the only thread that goes on a wait, right? whenever a required condition is met, the thread is awakened from sleep/wait using wakeOne()

wagmare
19th February 2009, 13:07
in this example, waitOne() is used to wake up Fortune Thread itself cuz that is the only thread that goes on a wait, right? whenever a required condition is met, the thread is awakened from sleep/wait using wakeOne()

thanks for reply ... i get it

i am not familiar in qt threads so only i ask this question ...
without it will create a problem? in this case if we dont try to do that what it will result ...
because i show the piece of code to my project manager and he ask the question why should you wait for another thread as only one thread is on progress so only i ask the question .

wagmare
19th February 2009, 13:17
here i am planning
=> a main thread class Dialog() having four buttons
=> a worker thread class Thread() will do all the operation of the buttons and emit the output ... single thread ..
=>i will call Thread() function calls in the Dialog() with arguments corresponding
to the user clicks button
=>the Thread in response emit corresponding signals from the argument


now in Thread() i have to use wakeOne() condition ... ? why ?

please give some suggestion ... i am still not cleared .. :)

talk2amulya
19th February 2009, 13:19
well, u r missing one very important thread :) the MAIN thread that runs with the main function..but thats not the point..the working of it is like..when u click the button, it gets disabled, thread is awakened(from wait) or started, it connects with the host, gets a fortune and emits a signal with the fortune string..the blocking client gets the signal, shows fortune or the error thrown and enables the button again..now u see the point? :)

wagmare
19th February 2009, 13:41
perfect .. and tomorrow i will expain him clearly .. thank you amulya ...

talk2amulya
19th February 2009, 13:44
u can thank my by clickin on that shiny "thanks" button down there ;) (i m not queer, just having a bet ;) )

wagmare
19th February 2009, 13:50
u can thank my by clickin on that shiny "thanks" button down there ;) (i m not queer, just having a bet ;) )

clicking a button is not like my words of thanks ... it echos dynamically to my helping friends .. :)