Multithreading problem

  • Thread starter Thread starter Boni
  • Start date Start date
B

Boni

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

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

Back
Top