Armoured wrote: Sat Feb 08, 2025 9:44 am
I need a function like InterlockedIncrement.
There are the following built-in functions.
__sync_add_and_fetch , __atomic_add_fetch
Code: Select all
CompilerIf #PB_Compiler_Backend <> #PB_Backend_C
CompilerError "Use C backend."
CompilerEndIf
Global a
Structure aa
i.i
EndStructure
Global b.aa
Procedure t(v)
Delay(Random(80, 50))
For i = 1 To 1000000
!__sync_add_and_fetch(&g_a, 1);
;!__sync_add_and_fetch(&g_b.f_i, 1);
Next
EndProcedure
t1 = CreateThread(@t(), 0)
t2 = CreateThread(@t(), 0)
t3 = CreateThread(@t(), 0)
t4 = CreateThread(@t(), 0)
WaitThread(t1)
WaitThread(t2)
WaitThread(t3)
WaitThread(t4)
MessageRequester("", "" + a)
;MessageRequester("", "" + b\i)