Threads with xojoscript

Hallo,

my program runs 2 xojo script in 2 threads.

Both scripts call a public function.

What’s happen if the scripts call the public function at the same time?

Thanks !!

Each thread gets its own copy of the function’s local variables, so as long as it doesn’t use any shared resources, there’s no problem. Access to any shared resource should be protected by a Semaphore or Critical Section.

I have declared a global semaphore object named Sem and a global integer variable named test.

To share (read / write) the common variable I use the follow function/sub

Shared Sub writedata(wdata as integer)
Sem.Signal
test = wdata
sem.Release
End Sub

Shared Function readdata() As integer
Dim rdata as integer
sem.Signal
rdata = data
sem.Release
return datatemp
End Function

Are these sub/function a good solution to share a global variable between 2 or more scripts?

Thanks!!!

I have declared a global semaphore object named Sem and a global integer variable named test.

To share (read / write) the common variable I use the follow function/sub

Shared Sub writedata(wdata as integer)
Sem.Signal
test = wdata
sem.Release
End Sub

Shared Function readdata() As integer
Dim rdata as integer
sem.Signal
rdata = test
sem.Release
return rdata
End Function

Are these sub/function a good solution to share a global variable between 2 or more scripts?

Thanks!!!