annuler
Affichage des résultats de 
Rechercher plutôt 
Vouliez-vous dire : 

Stopping a Notifier loop

I am a novice at using notifiers. In my application I have two parallel While loops; one is controlling the other by means of a notifier. The user presses the Done button. The master loop signals the slave loop using the Notifier; this signal passes a True to the stop sign. However, by the time this happens, the rest of the loop has already gone back around and waited on the notifier again. It is stuck at the notifier and hasn't really quit. I have an attempted solution, but it seems to involve a race condition because sometimes my application won't actually quit when the button is pressed. Although it will, of course, if I'm watching closely with a debugger.  )-:

 

Are there any good, established idioms out there for stopping a Notifier loop?

 

Thanks,

Ken

0 Compliments
Message 1 sur 6
4 001 Visites

My best guess, based on your description, is that you are releasing your notifier reference after your master loop stops executing.

 

You need to release it after your slave loop stops executing. 

 

When you say that "this signal passes a True value to the stop sign", to which loop do you refer?  The master or the slave?  If the slave loop receives a "True" value at its conditional terminal, it will stop.  It will not iterate around again.

 

Could you post your code?  I could probably be more helpful if I saw exactly what it is you're really doing.

0 Compliments
Message 2 sur 6
3 995 Visites

 


@DianeS wrote:

My best guess, based on your description, is that you are releasing your notifier reference after your master loop stops executing.

 

You need to release it after your slave loop stops executing.


I disagree - I find the easiest way to signal the slave loop to exit is to destroy the notifier when the master loop exits and use the resulting error condition to terminate the slave loop.  Wait on Notifier will return an error if the notifier on which it is waiting no longer exists.

0 Compliments
Message 3 sur 6
3 976 Visites

Yes, you can do it that way, but I dislike terminating a loop or an application by deliberately inducing an error.  I find it upsets my sense of neatness.  I know people do it, and that's fine if it works for them, but I'm not going to advise someone to do it that way.  Just personal philosophy there.

 

I also generally find that I have several conditions which can stop a loop (i.e. an error can occur, or a hardware fault can occur, or the process can finish, or the user can press "stop", etc.), so that's another reason I avoid using the error cluster to stop a loop.  It's easier to use an array of Booleans, one for each stop condition, and then query the array to determine what the code does next.

 

Shall we agree to disagree?  Smiley heureux

Message 4 sur 6
3 967 Visites

I also like to terminate simple slave processes by destroying the command messaging (queue, notifier) ref - it's elegant (no special messages, shift registers, comparisons...) and a generally accepted use of the Error/No Error case structure. More sophisticated methods are reserved for process instances where simply destroying the command ref does not meet framework requirements.

 

Needless to say, elegance is debatable.

0 Compliments
Message 5 sur 6
3 960 Visites

You might like my Community Nugget on Producer/Consumer

Although I use Queues, most of what is written is also applicable to notifiers.

 

Felix

0 Compliments
Message 6 sur 6
3 942 Visites