How to start a function in a new thread with a delay ?

General APL language issues

How to start a function in a new thread with a delay ?

Postby PGilbert on Tue Nov 30, 2021 2:10 am

I am trying to start a function in a new thread but with a delay of 1 second before beginning the execution. The following line does not work (nothing is executed). I could I do that ?

{⎕DL 1 ⋄ FOO}&0

Thanks in advance.

Pierre Gilbert
User avatar
PGilbert
 
Posts: 436
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: How to start a function in a new thread with a delay ?

Postby StefanoLanzavecchia on Tue Nov 30, 2021 7:13 am

That's for the same reason why
{[]DL 1 <> FOO }1
does not execute FOO: d-fns end execution at the first non assigned result. []DL 1 returns 1 and the execution does not proceed further. You may want to assign its result like so:
{ z<-[]DL 1 <> FOO }&1
User avatar
StefanoLanzavecchia
 
Posts: 109
Joined: Fri Oct 03, 2008 9:37 am

Re: How to start a function in a new thread with a delay ?

Postby PGilbert on Tue Nov 30, 2021 1:38 pm

Many thanks Stefano, it's working.
User avatar
PGilbert
 
Posts: 436
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: How to start a function in a new thread with a delay ?

Postby Adam|Dyalog on Sun Dec 05, 2021 10:01 am

As an alternative, consider delaying before launching the background thread:
      {FOO}&⎕DL 1
User avatar
Adam|Dyalog
 
Posts: 134
Joined: Thu Jun 25, 2015 1:13 pm

Re: How to start a function in a new thread with a delay ?

Postby PGilbert on Mon Dec 06, 2021 7:39 pm

Thanks Adam, will this way of doing will 'freeze' the current thread for 1 second before the execution of FOO starts in another thread ?
User avatar
PGilbert
 
Posts: 436
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: How to start a function in a new thread with a delay ?

Postby Adam|Dyalog on Mon Dec 06, 2021 7:42 pm

Yes, it will pause the main thread for a second, then continue by launching the background thread. Use whichever functionality it is you want.
User avatar
Adam|Dyalog
 
Posts: 134
Joined: Thu Jun 25, 2015 1:13 pm

Re: How to start a function in a new thread with a delay ?

Postby PGilbert on Mon Dec 06, 2021 7:50 pm

Merci Adam, this is answering my question.
User avatar
PGilbert
 
Posts: 436
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada


Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest