#1 2020-12-17 14:14:23

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,574
Website

InitializeCriticalSectionIfNeededAndEnter - fails with EThreadError

After a half of year of searching of the source of EThreadError what happens only on hi-load production  I finally found a reason

Function InitializeCriticalSectionIfNeededAndEnter is not atomic (even if it is inlined), so code

InitializeCriticalSectionIfNeededAndEnter(cs)
try 

finally
  LeaveCriticalSection(cs)  <------ fails here
end;

can fail (very-very rarely) on LeaveCriticalSection

@ab - I consider to remove  InitializeCriticalSectionIfNeededAndEnter function from mORMot2 sources, and may be even from mORMot (it not used in any of mORMot unit)

Last edited by mpv (2020-12-17 14:16:02)

Offline

#2 2020-12-17 14:42:48

pvn0
Member
From: Slovenia
Registered: 2018-02-12
Posts: 211

Re: InitializeCriticalSectionIfNeededAndEnter - fails with EThreadError

I think you meant to say the function is not thread safe, which it isn't. Luckily it's not used anywhere in the mORMot project so my thumbs up for removing it from stable and mormot2 branch. Nice find!

Offline

Board footer

Powered by FluxBB