Hi,
Has anyone had success using the multi-threading mutex primitives? I've
had limited success - I'll be presenting some basic routines at NYCJUG this
evening (18:00 EDT -
https://www.meetup.com/J-Dynamic-Functional-Programming/) - but have been
unable to run multiple threads on a real-life process without crashing J.
The following simplified demo seems to work OK but the version of this
where I do actual work crashes - with "Process shell<1> exited abnormally
with code 5" - after two to thirty repetitions.
MUTEX=: 10 T. 0 NB. Fast mutex
createThreads=: 3 : '{{ 0 T. '''' }} ^:y]'''''
qts=: 6!:0
createThreads 5
GVAR=: 100?@$1e6 NB. Initialize global threads will
consume
multiLockMsgUnlock=: 3 : 0
while. 0<#GVAR do.
tn=. ":3 T. '' NB. Thread number as char
varnm=: ' '-.~'threadVar',tn
smoutput 'Thread ',tn,' locking at ',":qts''
11 T. y
smoutput 'Thread ',tn,' locked at ',":qts''
(varnm,' GVAR')=: split GVAR
smoutput 'Thread ',tn,' unlocking at ',(":qts''),' with
',tn,'=',":".varnm
13 T. y
smoutput 'Thread ',tn,' unlocked at ',(":qts''),'; #GVAR=',":#GVAR
end.
)
NB. Start five processes (one line):
multiLockMsgUnlock t. '' MUTEX [ multiLockMsgUnlock t. '' MUTEX [
multiLockMsgUnlock t. '' MUTEX [ multiLockMsgUnlock t. '' MUTEX [
multiLockMsgUnlock t. '' MUTEX
The actual work I'm doing is on files, a list of whose names corresponds to
the GVAR vector above.
Any suggestions are welcome.
Cheers,
Devon
--
Devon McCormick, CFA
Quantitative Consultant
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm