How to use 2501⌶0

Using (or providing) Microsoft.NET Classes

How to use 2501⌶0

Postby PGilbert on Tue Aug 23, 2016 12:52 am

The new I beam 2501 is to discard thread on exit and must be used on the same thread that you want to discard. If you consider the 2 following functions:

      ∇BackgroundTask[⎕]∇
[0] BackgroundTask;mat
[1] mat←50 50⍴?2500⍴100

∇ExecTask[⎕]∇
[0] ExecTask;⎕USING;action;task
[1]
[2] ⎕USING,←'System.Threading.Tasks,mscorlib.dll' 'System,mscorlib.dll'
[3] action←⎕NEW Action(⎕OR'BackgroundTask')
[4] task←⎕NEW Task(action)
[5] task.Start ⍬


Each time 'ExecTask' is executed there is a new thread that is created (but not all the time and don't know why. Thread reuse ?). My question is where to put 2501⌶0 to discard the new thread on exit.

Thanks in advance
User avatar
PGilbert
 
Posts: 440
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: How to use 2501⌶0

Postby PGilbert on Tue Aug 23, 2016 2:37 pm

Found it, you need to put the 2501⌶0 as the last line of 'BackgroundTask' and the thread will be discarded. Looks like it is 'BackgroundTask' that is running on the new thread and obviously not 'ExecTask'. Like this:

      ∇BackgroundTask[⎕]∇
[0] BackgroundTask;mat
[1] mat←50 50⍴?2500⍴100
[2] {}2501⌶0


However each time you execute 'ExecTask' the new thread id that is created is increase by 1 (and discarded at the end of the execution of the program). Is there a upper limit to the thread id (tid) that when reached it will cause a problem ?
User avatar
PGilbert
 
Posts: 440
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: How to use 2501⌶0

Postby Vince|Dyalog on Wed Aug 24, 2016 8:56 am

Hi Pierre,

The tids will wrap around once they've reached the upper limit of 2,147,483,648.

The 2501 and 2502 I-Beams were implemented so that we don't get an ever increasing group of dormant threads which use resources.

The number of APL threads in use can be measured by looking at ⍴⎕TNUMS.

Regards,

Vince
Vince|Dyalog
 
Posts: 439
Joined: Wed Oct 01, 2008 9:39 am


Return to Microsoft.NET

Who is online

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