Shared Variable used as SyncLock

C

Core

Hello,

I am having a class that is used to spawn new threads off. In each of
them, I have a shared function that will generate an unique id off a
shared class variable. My question is whether using a shared object as a
synclock candidate will generate any race conditions. Thanks.

Core

Public class ThreadChilds
Private Shared syncLockObject As Object = New Object
Private Shared GlobalRequestBase As Integer

Private Shared Function GenerateNewRequestId() As Integer
Dim returnId As Integer = -1
SyncLock syncLockObject
If ThreadChilds.GlobalRequestBase >= 10000 Then
ThreadChilds.GlobalRequestBase = 0
Else
ThreadChilds.GlobalRequestBase =
ThreadChilds.GlobalRequestBase + 1
End If

returnId = ThreadChilds.GlobalRequestBase
End SyncLock

Return returnId
End Function
End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top