Anonymous user
Metered concurrency: Difference between revisions
m
Fixed lang tags.
(omit m4) |
m (Fixed lang tags.) |
||
Line 6:
The interface for the counting semaphore is defined in an Ada package specification:
<lang ada>
The ''Acquire'' entry has a condition associated with it. A task can only execute the ''Acquire'' entry when ''Lock_Count'' is less than ''Max''. This is the key to making this structure behave as a counting semaphore. This condition, and all the other aspects of ''Counting_Semaphore'' are contained in the package body.
<lang ada>
We now need a set of tasks to properly call an instance of ''Counting_Semaphore''.
<lang ada>
=={{header|ALGOL 68}}==
)</lang>▼
Output:
=={{header|C}}==
Line 259:
===Phobos with tools===
Using the scrapple.tools extension library for Phobos ..
<lang d>module metered;
import tools.threads, tools.log, tools.time, tools.threadpool;
Line 280 ⟶ 279:
for (int i = 0; i < 10; ++i)
done.acquire;
}</lang>
▲</lang>
=={{header|E}}==
This semaphore slightly differs from the task description; the release operation is not on the semaphore itself but given out with each acquisition, and cannot be invoked too many times.
}</lang>
=={{header|Java}}==
Line 392 ⟶ 390:
Python threading module includes a semaphore implementation. This code show how to use it.
<lang python>import time▼
▲import time
import threading
Line 429 ⟶ 426:
running = 0
for t in workers:
t.join()</lang>
=={{header|Raven}}==
Counting semaphores are built in:
Thread joining is automatic by default.
Line 526 ⟶ 522:
The number of concurrent jobs can be set by issuing that many echo '1''s at the begining to sem.
=={{header|Visual Basic .NET}}==
Line 550 ⟶ 546:
This code shows using a local semaphore. Semaphores can also be named, in which case they will be shared system wide.
<lang
{{omit from|TI-83 BASIC}} {{omit from|TI-89 BASIC}} <!-- Does not have concurrency or background processes. -->
|