⎕TGET
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 !
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 !
10 posts
• Page 1 of 1
⎕TGET
Could anybody say why in following example ⎕TGET ends only by timeout (15) but not when all threads are over.
How to do it correctly?
Sorry if this is a repetition of the question, I have not find the answer on forums.
Thanks
⍎ & '⎕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
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.
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.
-
Phil Last - Posts: 628
- Joined: Thu Jun 18, 2009 6:29 pm
- Location: Wessex
Re: ⎕TGET
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
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
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
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
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
-
Morten|Dyalog - Posts: 453
- Joined: Tue Sep 09, 2008 3:52 pm
Re: ⎕TGET
> What is the application?
I am researching for a thread safe method of tying a file, while maintaining a table of open files.
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
For something like that, it might be simpler to implement a "critical section" with:
:Hold 'TiedFiles'
... your logic ...
:EndHold
:Hold 'TiedFiles'
... your logic ...
:EndHold
-
Morten|Dyalog - Posts: 453
- Joined: Tue Sep 09, 2008 3:52 pm
Re: ⎕TGET
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
10 posts
• Page 1 of 1
Who is online
Users browsing this forum: Bing [Bot] and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group