Pausing a thread under program control

APL-related discussions - a stream of APL consciousness.
Not sure where to start a discussion ? Here's the place to be
Forum rules
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !

Pausing a thread under program control

Postby ray on Sat Jul 22, 2017 2:12 pm

I would like, in a multi-threaded system, to be able to "Pause" a thread under direct program control from another thread.

That is to change a selected thread's "Flag" from "Normal" to "Paused" (and back again).

Has anybody any ideas about how to achieve this?

Is there say, a "System Operator" (such as [Paused] ) one can call perhaps?. (As in the "Threads Tool Pop-Up Menu" that toggles a thread between being Paused and Normal.)

Anybody got any suggestions?

Thanks
Ray Cannon
Please excuse any smelling pisstakes.
User avatar
ray
 
Posts: 221
Joined: Wed Feb 24, 2010 12:24 am
Location: Blackwater, Camberley. UK

Re: Pausing a thread under program control

Postby crishog on Sun Jul 23, 2017 7:46 am

Have you tried using tokens? I have several instances where a child thread waits on a token, upon receiving it performs a specific action & then returns to wait on another instance of that token.

Works very well
crishog
 
Posts: 61
Joined: Mon Jan 25, 2010 9:52 am

Re: Pausing a thread under program control

Postby ray on Sun Jul 23, 2017 1:21 pm

Thanks for the suggestion.

I have used tokens in the past in a loop, testing for the existence of the token each time around the loop, but this thread does not run in/as a loop.

So I would have to test for the token in multiple locations, spread throughout the code of the thread.

I will be using tokens to control the information passing between threads.

What I want to do is SUSPEND and then RESUME processing of ONE of the threads.
Ray Cannon
Please excuse any smelling pisstakes.
User avatar
ray
 
Posts: 221
Joined: Wed Feb 24, 2010 12:24 am
Location: Blackwater, Camberley. UK

Re: Pausing a thread under program control

Postby crishog on Mon Jul 24, 2017 7:22 am

If you use a token with a negative value it can be repeatedly fetched without removing it from the pool. Therefore a few judiciously placed TGETs (using the positive value)in your sub-thread should be enough. As long at the value is in the pool the child thread will run.

Just TGET the negative value in the main thread - the child will pause when it gets to any of the TGETs of the positive value & you restart it by the main thread TPUTing the negative value back into the pool.
crishog
 
Posts: 61
Joined: Mon Jan 25, 2010 9:52 am

Re: Pausing a thread under program control

Postby ray on Mon Jul 24, 2017 2:05 pm

Thanks again.
You say "Therefore a few judiciously placed TGETs"
The problem is that I will need a TGET in every process taking significant time in my thread, a lot, not a few. (at least a dozen, maybe more).

Tokens are very usefull and powerfull at communicating between threads.

I need something more like an OnEvent trap : onTokenRecieved

I suppose I could check for a token in a loop, and on recipe, signal a user defined error which could be trapped and acted on by the thread.

Thanks anyway
Ray Cannon
Please excuse any smelling pisstakes.
User avatar
ray
 
Posts: 221
Joined: Wed Feb 24, 2010 12:24 am
Location: Blackwater, Camberley. UK


Return to APL Chat

Who is online

Users browsing this forum: No registered users and 1 guest