I see plenty of correspondents have had a go already.
However,  a few examples of use might be helpful.   I have just found
t. & T. in NuVoc, having assumed they wouldn't be there yet,  so thanks for
that.

Trying t =: t.''  as suggested elsewhere,  and T =:  T.&'',  in a session with
   T each 1 2 3 4   NB. ie 3 threads
+-+-----+-++
|3|3 1 2|0||
+-+-----+-++

I find
   timer'Sa 1000'    NB. returns correct result for y=1000
+--------+--------+
|0.266998|37048340|
+--------+--------+
   timer'Sa t 1000'   NB. no time detected
++--------+
||37048340|
++--------+
   ts'Sa 1000'
0.273682 481344
   ts'Sa t 1000'
1.86e_5 1408

But trying to capture the result of Sa hangs:
   ts'q =: Sa t 1000'
.... hourglass ...

in Windows 11.    Using the J break batch file doesn't appear to work.

I've now tried timex =: 6!:2 rather than ts =: 6!:2 , 7!:2@]
with a bit more success, which suggests the space query is causing the hang:

   timex'q=: Sa 16000'   NB. longer time so I can try stopwatching as below
27.1941
   erase'q'
1
   timex'q=: Sa t 16000'   NB. supersonic!?!?
2.41e_5
   q          NB. no! - this took about 25 seconds to return a boxed value,  from a pyx, I suppose:
+-----------+
|38245553964|
+-----------+

So the session hangs for around 25 seconds while the value for q is found.

(Sa is my best effort so far,  and far too slow so far,  for Project Euler Problem 791,
https://projecteuler.net/problem=791 , in case of interest.)

FWIW,
   JVERSION
Engine: j904/j64avx2/windows
Beta-a: commercial/2022-04-09T17:57:22
Library: 9.04.01
Qt IDE: 2.0.3/6.2.4(6.2.4)
Platform: Win 64
Installer: J904 install
InstallPath: c:/d/j904-beta
Contact: www.jsoftware.com

Thanks,

Mike



On 09/04/2022 20:04, Henry Rich wrote:
The big news in J904 is multithreading.  J verbs can now be run in different cores, sharing the J global namespaces.

[A version of J with limited support for multithreading was revealed last year by John Ference of Monument AI.  John's work was an important proof of concept, but the J904 version is an independent development using pthreads instead of OpenMP.  John has agreed with Jsoftware to give Jsoftware access to the code and testcases used in his work.  We have not used the code.]

Two primitives support multithreading:

(0 T. '')   creates a thread on a new core.  A thread running a verb is called a /task/. Even if you don't plan to create tasks, you should create threads to allow JE to use them for its own purposes.

([x] u t. '' y) executes ([x] <@:u y) as a task to produce a boxed result.  The thread that executed t. continues to run.  But the result is a special kind of box called a /pyx/.

['pyx' is Greek for box, and has been brought into English on occasion when a word has been needed for a special box.  The most recent such borrowing until now is for the box used by the Royal Mint to hold coins for assay.]

A pyx looks on the outside like any other box.  You can pass it as an argument.  But as soon as you look inside it, your thread is blocked until the task producing the pyx's value has completed. Then you see the value, and your thread continues.

Tasks share the global namespaces and thus can freely read, write, stomp on, and delete names visible to other tasks.

We encourage you to experiment with threads and tasks.  We are sure that a layer of synchronizing primitives - semaphores, locks, and mutexes - will be needed, but we would like to get practical experience with tasks before we implement them.  Suggestions welcome.

Henry Rich








--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to