Data update

This commit is contained in:
Ingy döt Net 2026-02-01 16:33:20 -08:00
parent 5150844a7d
commit 4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions

View file

@ -1,9 +0,0 @@
package Semaphores is
protected type Counting_Semaphore(Max : Positive) is
entry Acquire;
procedure Release;
function Count return Natural;
private
Lock_Count : Natural := 0;
end Counting_Semaphore;
end Semaphores;

View file

@ -1,40 +0,0 @@
package body Semaphores is
------------------------
-- Counting_Semaphore --
------------------------
protected body Counting_Semaphore is
-------------
-- Acquire --
-------------
entry Acquire when Lock_Count < Max is
begin
Lock_Count := Lock_Count + 1;
end Acquire;
-----------
-- Count --
-----------
function Count return Natural is
begin
return Lock_Count;
end Count;
-------------
-- Release --
-------------
procedure Release is
begin
if Lock_Count > 0 then
Lock_Count := Lock_Count - 1;
end if;
end Release;
end Counting_Semaphore;
end Semaphores;

View file

@ -1,37 +0,0 @@
with Semaphores;
with Ada.Text_Io; use Ada.Text_Io;
procedure Semaphores_Main is
-- Create an instance of a Counting_Semaphore with Max set to 3
Lock : Semaphores.Counting_Semaphore(3);
-- Define a task type to interact with the Lock object declared above
task type Worker is
entry Start (Sleep : in Duration; Id : in Positive);
end Worker;
task body Worker is
Sleep_Time : Duration;
My_Id : Positive;
begin
accept Start(Sleep : in Duration; Id : in Positive) do
My_Id := Id;
Sleep_Time := Sleep;
end Start;
--Acquire the lock. The task will suspend until the Acquire call completes
Lock.Acquire;
Put_Line("Task #" & Positive'Image(My_Id) & " acquired the lock.");
-- Suspend the task for Sleep_Time seconds
delay Sleep_Time;
-- Release the lock. Release is unconditional and happens without suspension
Lock.Release;
end Worker;
-- Create an array of 5 Workers
type Staff is array(Positive range 1..5) of Worker;
Crew : Staff;
begin
for I in Crew'range loop
Crew(I).Start(2.0, I);
end loop;
end Semaphores_Main;

View file

@ -1,65 +0,0 @@
sequence sems
sems = {}
constant COUNTER = 1, QUEUE = 2
function semaphore(integer n)
if n > 0 then
sems = append(sems,{n,{}})
return length(sems)
else
return 0
end if
end function
procedure acquire(integer id)
if sems[id][COUNTER] = 0 then
task_suspend(task_self())
sems[id][QUEUE] &= task_self()
task_yield()
end if
sems[id][COUNTER] -= 1
end procedure
procedure release(integer id)
sems[id][COUNTER] += 1
if length(sems[id][QUEUE])>0 then
task_schedule(sems[id][QUEUE][1],1)
sems[id][QUEUE] = sems[id][QUEUE][2..$]
end if
end procedure
function count(integer id)
return sems[id][COUNTER]
end function
procedure delay(atom delaytime)
atom t
t = time()
while time() - t < delaytime do
task_yield()
end while
end procedure
integer sem
procedure worker()
acquire(sem)
printf(1,"- Task %d acquired semaphore.\n",task_self())
delay(2)
release(sem)
printf(1,"+ Task %d released semaphore.\n",task_self())
end procedure
integer task
sem = semaphore(4)
for i = 1 to 10 do
task = task_create(routine_id("worker"),{})
task_schedule(task,1)
task_yield()
end for
while length(task_list())>1 do
task_yield()
end while