Active object: Difference between revisions
Content added Content deleted
(C++ spacing) |
(→{{header|J}}: dedicated thread for integrator object) |
||
Line 1,465: | Line 1,465: | ||
First column is time relative to start of processing, second column is object's output at that time. |
First column is time relative to start of processing, second column is object's output at that time. |
||
=== Using a task thread === |
|||
Variant using an independent task thread: |
|||
<syntaxhighlight lang=J>delay=: 6!:3 |
|||
task=: {{ |
|||
obj=. '' conew 'integra' |
|||
F__obj=: 1 o. o. |
|||
delay 2 |
|||
F__obj=: 0: |
|||
delay 0.5 |
|||
s=. S__obj |
|||
destroy__obj'' |
|||
s |
|||
}} |
|||
coclass'integra' |
|||
reqthreads=: {{ 0&T.@''^:(0>.y-1 T.'')0 }} |
|||
time=: 6!:1 |
|||
F=: 0: |
|||
K=: S=: SHUTDOWN=: 0 |
|||
create=: {{ |
|||
reqthreads cores=. {.8 T. '' |
|||
integrator t. '' T=: time'' |
|||
}} |
|||
destroy=: {{ codestroy '' [ SHUTDOWN=: 1 }} |
|||
integrator=: {{ |
|||
while. -.SHUTDOWN do. |
|||
t=. time'' |
|||
k=. F t |
|||
S=: S + (k+K)*t-T |
|||
T=: t |
|||
K=: k |
|||
end. |
|||
}} |
|||
</syntaxhighlight> |
|||
This exhibits more timing variance because of the loose coupling of scheduling between threads: |
|||
<syntaxhighlight lang=J> task'' |
|||
0.0194745 |
|||
task'' |
|||
_4.40316e_15 |
|||
task'' |
|||
0.00874017 |
|||
task'' |
|||
_0.0159841 |
|||
</syntaxhighlight> |
|||
=={{header|Java}}== |
=={{header|Java}}== |