PB 6.30 b4 - API calls and multithreading

All bugs related to new C backend
User_Russian
Addict
Addict
Posts: 1601
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

PB 6.30 b4 - API calls and multithreading

Post by User_Russian »

Code: Select all

Procedure RunOnce()
  Protected Res=#False, r, ProgID.s
  
  ProgID=UCase(StringFingerprint(GetCurrentDirectory(), #PB_Cipher_SHA1))
  r = CreateSemaphore_(#Null, 0, 1, "Semaphore"+ProgID)
  If r<>0
    If GetLastError_()=#ERROR_ALREADY_EXISTS ; Копия приложения уже запущена.
      CloseHandle_(r)
      Res=#True
    EndIf
  EndIf
  ProcedureReturn Res
EndProcedure

UseSHA1Fingerprint()
Debug RunOnce()
Debug RunOnce()
When you run the code, the debug window should show
0
1
But if you turn it on "Create threadsafe executable" then this result will be in the debug window
0
0
This means that when multithreading is enabled, the code does not work correctly.
User_Russian
Addict
Addict
Posts: 1601
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: PB 6.30 b4 - API calls and multithreading

Post by User_Russian »

Code: Select all

// r = CreateSemaphore_(#Null, 0, 1, "Semaphore"+ProgID)
SYS_PushStringBasePosition();
SYS_PushStringBasePosition();
SYS_CopyString(_S1);
SYS_CopyString(v_progid);
SYS_IncrementStringBasePosition();
integer p2=(integer)SYS_PopStringBasePositionValueNoUpdate();
integer r0=f_createsemaphore_(0,0,1,p2);
SYS_PopStringBasePositionUpdate();
v_r=r0;
// 
// If r<>0
if (!((v_r!=0))) { goto no2; }
// If GetLastError_()=#ERROR_ALREADY_EXISTS 
integer r1=f_getlasterror_();
I think the problem is inside the function SYS_PopStringBasePositionUpdate() which calls some WinAPI function that resets the result GetLastError() and it returns 0.
Post Reply