473,395 Members | 1,692 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,395 software developers and data experts.

Multithreading problem

Dear all,
it seems that I have a multithreadng problem. I am not sure.
class A
UID as integer
shared ctr as integer=0
sub new()
UID=ctr
ctr+=1
end sub

end

Sometime I get 2 A objects with the same UID. I don't explicitely start
thread. Also it it possible that my class library is called from many
threads.
In order to find out, if it is really threading problem I need unique some
sort thread ID, which will be unique for each thread ?
But I can find only domainID in threading.thread.
Please is it possible to get some unique threadID or hashcode or something
else in .NET 1.1?
Nov 21 '05 #1
6 978
Hi,

SyncLock prevents multiple threads from executing the same code at
the same time.

http://msdn.microsoft.com/library/de...tmsynclock.asp

Ken
---------------------------
"Boni" <oilia@nospam> wrote in message
news:OZ**************@TK2MSFTNGP12.phx.gbl...
Dear all,
it seems that I have a multithreadng problem. I am not sure.
class A
UID as integer
shared ctr as integer=0
sub new()
UID=ctr
ctr+=1
end sub

end

Sometime I get 2 A objects with the same UID. I don't explicitely start
thread. Also it it possible that my class library is called from many
threads.
In order to find out, if it is really threading problem I need unique some
sort thread ID, which will be unique for each thread ?
But I can find only domainID in threading.thread.
Please is it possible to get some unique threadID or hashcode or something
else in .NET 1.1?

Nov 21 '05 #2
Hi Ken
I know SyncLock. The problem is that I am not really sure if it is because
of multithreading. So I would like to output threadID or some other unique
thread info.
Is it possible?
Thanks,
Boni
"Ken Tucker [MVP]" <vb***@bellsouth.net> schrieb im Newsbeitrag
news:OB**************@TK2MSFTNGP15.phx.gbl...
Hi,

SyncLock prevents multiple threads from executing the same code at
the same time.

http://msdn.microsoft.com/library/de...tmsynclock.asp

Ken
---------------------------
"Boni" <oilia@nospam> wrote in message
news:OZ**************@TK2MSFTNGP12.phx.gbl...
Dear all,
it seems that I have a multithreadng problem. I am not sure.
class A
UID as integer
shared ctr as integer=0
sub new()
UID=ctr
ctr+=1
end sub

end

Sometime I get 2 A objects with the same UID. I don't explicitely start
thread. Also it it possible that my class library is called from many
threads.
In order to find out, if it is really threading problem I need unique
some sort thread ID, which will be unique for each thread ?
But I can find only domainID in threading.thread.
Please is it possible to get some unique threadID or hashcode or
something else in .NET 1.1?


Nov 21 '05 #3
To safely do what you want, try Threading.Interlocked.Increment().
Also, be advised that static applies to an AppDomain, a gotcha for the unwary.

Nov 21 '05 #4
On 2005-09-05, AMercer <AM*****@discussions.microsoft.com> wrote:
To safely do what you want, try Threading.Interlocked.Increment().
That won't fix the problem, since it's possible for objects in different
threads to acquire the same UID previous to the atomic increment.

Also, be advised that static applies to an AppDomain, a gotcha for the unwary.

Nov 21 '05 #5
> That won't fix the problem, since it's possible for objects in different
threads to acquire the same UID previous to the atomic increment.


in the constructor,
uid=Threading.Interlocked.Increment(ctr)
gets the job done for all threads in the same appdomain.

Nov 21 '05 #6
On 2005-09-05, AMercer <AM*****@discussions.microsoft.com> wrote:
That won't fix the problem, since it's possible for objects in different
threads to acquire the same UID previous to the atomic increment.


in the constructor,
uid=Threading.Interlocked.Increment(ctr)
gets the job done for all threads in the same appdomain.


You're right of course. Somehow I got focused on the fact that the
assignment was on a different line in the original post and commented
on that.

Nov 21 '05 #7

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

Similar topics

11
by: Mark Yudkin | last post by:
The documentation is unclear (at least to me) on the permissibility of accessing DB2 (8.1.5) concurrently on and from Windows 2000 / XP / 2003, with separate transactions scope, from separate...
16
by: Robert Zurer | last post by:
Can anyone suggest the best book or part of a book on this subject. I'm looking for an in-depth treatment with examples in C# TIA Robert Zurer robert@zurer.com
6
by: Michael C | last post by:
Hello Can someone please tell me what I'm doing wrong? I'm writing an application that should be using callbacks to perform asynchronous calls to the Win32 API. Problem is it never reaches my...
5
by: sarge | last post by:
I would like to know how to perform simple multithreading. I had created a simple form to test out if I was multithreading properly, but got buggy results. Sometime the whole thig would lock up...
2
by: shonend | last post by:
**** sorry about the length of the message. If you can't read the whole thing and still willing to help, read the last 2 paragraphs where the main problem is described. The introduction story is...
2
by: Multithreading problem in vb.net | last post by:
Greetings, I am new to multithreading and I am trying to implement it in my app. This application is distributed application which needs to refresh every say 5 secs to show some activities in...
4
by: Michael | last post by:
Hi, I am trying to create a multithreaded VB 2005 application which attempts to create a new thread per Domain Controller (DC) in my environment. Each thread connects to its allocated DC and...
0
by: denis.cornehl | last post by:
Hi, I have an unusual Problem with DB2. It is DB2 Version 7 and Fixpack 13 under Windows. We have written an application server which is accessing db2 via c++ and the cli interface. We used...
2
by: Pradnya Patil | last post by:
hi , I am trying to draw ' html div-tag ' on the screen which will resemble a rectangle through vb.net code. I want it to be drawn faster...so I introduced multithreading using Threadpool. I...
7
by: Ray | last post by:
Hello, Greetings! I'm looking for a solid C++ multithreading book. Can you recommend one? I don't think I've seen a multithreading C++ book that everybody thinks is good (like Effective C++ or...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.