473,327 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Shared Variable used as SyncLock

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
Jun 29 '07 #1
1 2629
>My question is whether using a shared object as a
synclock candidate will generate any race conditions.
No, not that in itself.

Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jun 30 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: tom | last post by:
Hello, I'm using the ms data access application blocks. My question is about the fact that everywhere shared methods are used. Does this mean that when more than 1 user at the same time...
6
by: Paul | last post by:
Hi. Just trying to find out the best approach as I beleive it might give me problems later on down the road. I have an ASP.NET application which references a shared database class which...
3
by: Henri | last post by:
1) Do Shared methods always need to be synchronised to be thread-safe? 2) Why must SyncLock be used with a reference type? I can't get the relation between threads and a type. Thanks for your...
1
by: Henri | last post by:
Hi, I'm using a custom class in my ASP.NET which has a Shared property. I don't want this Shared property to be shared between users because of thread concurrent accesses problems. I just want it...
9
by: Bob Day | last post by:
VS 2003, vb.net , sql msde... I have an application with multiple threads running. Its a telephony application where each thread represents a telephone line. For code that would be the same...
3
by: Bob Day | last post by:
Ok, I have done a lot of reading(of the newsgroup answers, help files and MSDN articles) of synclock. I understand what you are saying in the newsgroup, and it is very helpful. It does, however,...
2
by: Aaron Cutlip | last post by:
I have been looking all over and have seen many possible ways to create a Syncronized Shared Function in VB.NET, but I would like some advice that will make my life easier. Given the following...
1
by: =?Utf-8?B?QXJuZSBHYXJ2YW5kZXI=?= | last post by:
I have an ASP.net 2.0 website. This website have a module; Public Module myModule. Is all the data in this module shared and not thread safe? I would like explicitly create a shared object in an...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.