Page 1 of 1
PB 6.30 b4 - API calls and multithreading
Posted: Tue Oct 28, 2025 12:36 pm
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.
Re: PB 6.30 b4 - API calls and multithreading
Posted: Tue Oct 28, 2025 7:31 pm
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.