https://www.rosettacode.org/wiki/Metered_concurrency

I wanted to put together a more serious J implementation of the
rosettacode metered concurrency task.

Unfortunately, either (a) I do not understand how the threading
primitives are supposed to work, or (b) they are not working properly.

metcon=: {{
  lock=: 10 T. 0
  sleep=: 6!:3
metcon=: {{
  lock=: 10 T. 0
  sleep=: 6!:3
  task=. {{
    11 T. lock;_            NB. wait
    sleep 2
    echo r=.'Task ',y,&":' has the semaphore'
    13 T. lock              NB. release
    r rplc 'has';'had'
  }}
  0&T.@'' each i.0>4-1 T.'' NB. ensure at least four threads
  r=. task t.''"0 i.10      NB. dispatch 10 tasks
  #each r                   NB. wait for completion
  14 T. lock                NB. discard lock
  r
}}
I expect this to take about 20 seconds (because of the use of 6!:3)
and run ten tasks in 3 of the four guaranteed threads.

Instead, what I get is this:

   metcon''
Task 1 has the semaphore
Task 3 has the semaphore
Task 5 has the semaphore
Task 7 has the semaphore
Task 9 has the semaphore
|value error
|       #each r

So it looks like half of my tasks are getting lost somewhere, and it
looks like all of the results from those tasks are getting lost
somewhere.

   JVERSION
Engine: j904/j64avx2/windows
Beta-d: commercial/2022-05-19T20:39:35
Library: 9.04.01
Qt IDE: 2.0.3/6.2.4(6.2.4)
Platform: Win 64
Installer: J904 install
InstallPath: c:/other/j904
Contact: www.jsoftware.com

Thanks,

-- 
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to