Page 1 of 1
⎕TGET
Posted: Tue Feb 09, 2016 9:00 am
by nikll
Could anybody say why in following example
⎕TGET ends only by timeout (15) but not when all threads are over.
⍎ & '⎕DL 5 ⋄ ''1 is over'' '
⍎ & '⎕DL 5 ⋄ ''2 is over'' '
⍎ & '⎕DL 5 ⋄ ''3 is over'' '
15 ⎕TGET ⎕TCNUMS 0
1 is over
3 is over
2 is over
How to do it correctly?
Sorry if this is a repetition of the question, I have not find the answer on forums.
Thanks
Re: ⎕TGET
Posted: Tue Feb 09, 2016 10:45 am
by Phil Last
Although designed to help navigate the tortuous paths they lead us down, ⎕TGET has little if any direct interaction with threads.
Thread numbers are not tokens although in some circumstances it might be useful to use them as such.
In your example ⎕TGET is awaiting three tokens of types that happen to correspond to the thread numbers arbitrarily assigned previously. Unless you could predict what thread numbers were to be assigned and ⎕TPUT corresponding tokens beforehand; or ⎕TPUT each as it was assigned, you will always wait for the full timeout without which ⎕TGET would await an interrupt.
Re: ⎕TGET
Posted: Tue Feb 09, 2016 2:18 pm
by DanB|Dyalog
I think what you want is ⎕TSYNC:
Code: Select all
T←⍎ & '⎕DL 5 ⋄ ''1 is over'' '
T,←⍎ & '⎕DL 5 ⋄ ''2 is over'' '
T,←⍎ & '⎕DL 5 ⋄ ''3 is over'' '
⎕tsync T
1 is over 2 is over 3 is over
Re: ⎕TGET
Posted: Wed Feb 10, 2016 7:32 am
by nikll
thank you, very much for the really helpful answers. Indeed I need the ⎕tsync!
Re: ⎕TGET
Posted: Mon Mar 14, 2016 2:20 pm
by ArrayMac227
This discussion thread begs a question: is there material about using all these quadT functions besides in the reference books? I'm guessing these can be used to build thread-safe code, and I'm sure experimentation will bear fruit, but just in case this path has been covered before...
Re: ⎕TGET
Posted: Tue Mar 15, 2016 9:37 am
by crishog
I'm not aware of any more documentation, but Dan might have some - I've got a large number of examples because DFS uses tokens to co-ordinate its threads
Also it uses the optional ability to associate a value with a token to pass information between threads
Re: ⎕TGET
Posted: Wed Mar 16, 2016 7:08 am
by Morten|Dyalog
ArrayMac227 wrote:is there material about using all these quadT functions besides in the reference books?
The distributed workspace lift.dws contains a worked example of a system of lifts accepting passangers and transporting them to different floors.
What is the application? If it is computational, you might want to look at Futures and Isolates, to get proper multi-processing on multi-core machines (or clusters of machines):
http://docs.dyalog.com/14.1/Dyalog%20APL%20Experimental%20Functionality%20-%20Parallel%20Language%20Features.pdf
Re: ⎕TGET
Posted: Wed Mar 16, 2016 3:27 pm
by ArrayMac227
> What is the application?
I am researching for a thread safe method of tying a file, while maintaining a table of open files.
Re: ⎕TGET
Posted: Wed Mar 16, 2016 4:25 pm
by Morten|Dyalog
For something like that, it might be simpler to implement a "critical section" with:
:Hold 'TiedFiles'
... your logic ...
:EndHold
Re: ⎕TGET
Posted: Sat Mar 19, 2016 2:15 pm
by ArrayMac227
Thanks, Morten, for the pointer. It reminds me that there is always a human component to documentation.