This reliably crashes J for me.

metcon=: {{
  lock=: 10 T. 0
  sleep=: 6!:3
  task=. {{
    echo 'Task ',y,&":' waiting...'
    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
  echo (":1 T. ''),' threads'
  r=. > task f. t.''"0 i.10    NB. dispatch and wait for 10 tasks
  14 T. lock                NB. discard lock
  r
}}
metcon''

Sometimes I even get a popup, like:

---------------------
jqt.exe - Application Error

The instruction at 0x00007FF85D0007F4 referenced memory at
0x0000000000000064. The memory could not be read.

Click on OK to terminate the program.

                                                                      [OK]
---------------------

Replacing 11 T. lock;_ with 11 T. lock is nice (but it still crashes).

FYI,

-- 
Raul

On Wed, Jun 1, 2022 at 7:02 PM Elijah Stone <[email protected]> wrote:
>
> In the mean time, you can work around the issue by using task f..
>
> On Wed, 1 Jun 2022, Raul Miller wrote:
>
> > Oops, bad copy and paste
> >
> > Ignore the first (incomplete) declaration of metcon.
> >
> > Actually, please treat the declaration at
> > http://www.jsoftware.com/pipermail/beta/2022-June/010566.html as
> > canonical for this issue.
> >
> > Thanks,
> >
> > --
> > Raul
> >
> > On Wed, Jun 1, 2022 at 3:57 PM Raul Miller <[email protected]> wrote:
> >>
> >> 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
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to