You are not logged in.
I know that I can inherit TSynThreadPool and add a TaskCount property in the subclass, increase the Property by 1 after Push, decrement it by 1 when the Task completes, and use TLightLock to make it thread safe.
But I want to know if there is an easier way? I tried the RunningThreads attribute, but it didn’t work. It is always consistent with the parameters of Create(NumberOfThreads) and cannot be used to confirm the number of Tasks being executed.
Here is my code: https://gist.github.com/zen010101/def68 … 0b028d70d2
Offline
When WINIOCP is not used, I can determine whether all Tasks have been executed by judging whether PendingContextCount is 0.
Offline
Please try
https://github.com/synopse/mORMot2/commit/e46982c6
Now you should have access to a TSynThreadPool.PendingContextCount property even with IOCP.
Note: InterlockedIncrement/Decrement() are better than a lock if you just need atomic access to an integer.
Offline
Confirm that the PendingContextCount property can also be used in IOCP mode as the condition for determining the completion of all Task executions.
Offline
New bug:
When TSynThreadPool is destroyed in the middle of executing the tasks, the TaskAbort is not called, but in Linux, all works well.
see this, compile it for windows and linux to see the differences: https://gist.github.com/zen010101/def68 … 0b028d70d2
The possible issue might be here:
destructor TSynThreadPool.Destroy;
var
i: PtrInt;
endtix: Int64;
begin
fTerminated := true; // fWorkThread[].Execute will check this flag
try
{$ifdef USE_WINIOCP}
// notify the threads we are shutting down
for i := 0 to fWorkThreadCount - 1 do
IocpPostQueuedStatus(fRequestQueue, 0, nil, {ctxt=}nil);
// TaskAbort() is done in Execute when fTerminated = true
{$else}
Offline
The behavior did not change. Previous code did the same.
So it is not a regression, it is a long-standing bug.
Edit:
Should be fixed with
https://github.com/synopse/mORMot2/commit/3db4b9e4
Offline
Confirm fixed.
Last edited by zen010101 (2024-10-14 14:23:36)
Offline
New bug:
When creating a thread pool and passing a larger thread value in IOCP mode, TSynThreadPool.Free will enter an infinite loop and block the process.
Here is the demo: https://gist.github.com/zen010101/def68 … 0b028d70d2
Offline
In fact, there is no infinite loop but a 30 seconds timeout in TSynThreadPool.Destroy.
Please try with
https://github.com/synopse/mORMot2/commit/d8b5ce76
Offline
Confirmed fixed. :-)
Offline