I have a queue in which I can wrap various threads, so I can assure two things:
- The request is processed one by one.
- The request is processed in ascending order.
The second point is important. Otherwise, a simple critical section is sufficient. I have different query groups, and only within one group these points must be executed. Requests from different groups can be performed simultaneously.
It looks like this:
FTaskQueue.Enqueu('MyGroup');
try
Do Something (running in context of some thread)
finally
FTaskQueue.Dequeu('MyGroup');
end;
EDIT : I removed the actual implementation because it hides the problem I want to solve
, - Indy, HTTP-. . () . (, , ), . , , . , .
(ususal) ? , Enqueue Dequeue , preserverd. , .
: Enqueue/Dequeue
- :
procedure Enqueue;
begin
EnterCriticalSection(FCritSec);
try
DoEnqueue;
finally
LeaveCriticalSection(FCritSec);
end;
BlockTheCurrentThread;
end;
procedure Dequeue;
begin
EnterCriticalSection(FCritSec);
try
DoDequeue;
UnblockTheNextThread;
finally
LeaveCriticalSection(FCritSec);
end;
end;
, . , - Enqueue, , . , () . , . , , . , , .