⎕TGET

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 !
Post Reply
nikll
Posts: 13
Joined: Sat Oct 17, 2015 1:35 pm

⎕TGET

Post 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
User avatar
Phil Last
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: ⎕TGET

Post 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.
DanB|Dyalog

Re: ⎕TGET

Post 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
nikll
Posts: 13
Joined: Sat Oct 17, 2015 1:35 pm

Re: ⎕TGET

Post by nikll »

thank you, very much for the really helpful answers. Indeed I need the ⎕tsync!
ArrayMac227
Posts: 62
Joined: Sat Sep 12, 2015 1:40 pm

Re: ⎕TGET

Post 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...
crishog
Posts: 61
Joined: Mon Jan 25, 2010 9:52 am

Re: ⎕TGET

Post 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
User avatar
Morten|Dyalog
Posts: 460
Joined: Tue Sep 09, 2008 3:52 pm

Re: ⎕TGET

Post 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
ArrayMac227
Posts: 62
Joined: Sat Sep 12, 2015 1:40 pm

Re: ⎕TGET

Post 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.
User avatar
Morten|Dyalog
Posts: 460
Joined: Tue Sep 09, 2008 3:52 pm

Re: ⎕TGET

Post by Morten|Dyalog »

For something like that, it might be simpler to implement a "critical section" with:

:Hold 'TiedFiles'
... your logic ...
:EndHold
ArrayMac227
Posts: 62
Joined: Sat Sep 12, 2015 1:40 pm

Re: ⎕TGET

Post by ArrayMac227 »

Thanks, Morten, for the pointer. It reminds me that there is always a human component to documentation.
Post Reply