Metered concurrency: Difference between revisions
Content deleted Content added
→{{header|Groovy}}: new solution |
Added zkl |
||
Line 1,357: | Line 1,357: | ||
Dim oldCount = sem.Release() 'Returns a resource to the pool |
Dim oldCount = sem.Release() 'Returns a resource to the pool |
||
'oldCount has the Semaphore's count before Release was called</lang> |
'oldCount has the Semaphore's count before Release was called</lang> |
||
=={{header|zkl}}== |
|||
Semaphores are built in. |
|||
<lang zkl>fcn job(name,sem){ |
|||
name.println(" wait"); sem.acquire(); |
|||
name.println(" go"); Atomic.sleep(2); |
|||
sem.release(); name.println(" done") |
|||
} |
|||
// start 3 threads using the same semphore |
|||
s:=Thread.Semaphore(1); |
|||
job.launch("1",s); job.launch("2",s); job.launch("3",s);</lang> |
|||
{{out}} |
|||
<pre> |
|||
2 wait |
|||
2 go |
|||
1 wait |
|||
3 wait |
|||
2 done |
|||
1 go |
|||
1 done |
|||
3 go |
|||
3 done |
|||
</pre> |
|||
{{omit from|TI-83 BASIC}} {{omit from|TI-89 BASIC}} <!-- Does not have concurrency or background processes. --> |
{{omit from|TI-83 BASIC}} {{omit from|TI-89 BASIC}} <!-- Does not have concurrency or background processes. --> |