⎕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 !

⎕TGET

Postby nikll on Tue Feb 09, 2016 9:00 am

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

Re: ⎕TGET

Postby Phil Last on Tue Feb 09, 2016 10:45 am

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

Re: ⎕TGET

Postby DanB|Dyalog on Tue Feb 09, 2016 2:18 pm

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

Re: ⎕TGET

Postby nikll on Wed Feb 10, 2016 7:32 am

thank you, very much for the really helpful answers. Indeed I need the ⎕tsync!
nikll
 
Posts: 13
Joined: Sat Oct 17, 2015 1:35 pm

Re: ⎕TGET

Postby ArrayMac227 on Mon Mar 14, 2016 2:20 pm

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

Re: ⎕TGET

Postby crishog on Tue Mar 15, 2016 9:37 am

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

Re: ⎕TGET

Postby Morten|Dyalog on Wed Mar 16, 2016 7:08 am

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

Re: ⎕TGET

Postby ArrayMac227 on Wed Mar 16, 2016 3:27 pm

> What is the application?

I am researching for a thread safe method of tying a file, while maintaining a table of open files.
ArrayMac227
 
Posts: 62
Joined: Sat Sep 12, 2015 1:40 pm

Re: ⎕TGET

Postby Morten|Dyalog on Wed Mar 16, 2016 4:25 pm

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

:Hold 'TiedFiles'
... your logic ...
:EndHold
User avatar
Morten|Dyalog
 
Posts: 453
Joined: Tue Sep 09, 2008 3:52 pm

Re: ⎕TGET

Postby ArrayMac227 on Sat Mar 19, 2016 2:15 pm

Thanks, Morten, for the pointer. It reminds me that there is always a human component to documentation.
ArrayMac227
 
Posts: 62
Joined: Sat Sep 12, 2015 1:40 pm


Return to APL Chat

Who is online

Users browsing this forum: Bing [Bot] and 1 guest