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
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