Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2007

Tip: Looking for answers? Try searching our database.

multithreading and procedures...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
buu - 16 Jul 2007 17:58 GMT
I have a multitheaded app. in wich I do not user AutoResetEvent for handling
classes that are common for all threads.

now, I have a procedure in a common class that looks like this:

Public Sub aa(byref Object1 as cObject)

synclock Objekt2
   //radi nesto sa objektom 1
end synclock

end sub

But, is it possible that because there's no AutoResetEvent, that one thread
enters SyncLock block, and during that period another thread enters Sub, and
made changes in reference to Object1 causing wrong data in 1st thread?
Peter Duniho - 16 Jul 2007 18:42 GMT
> [...]
> But, is it possible that because there's no AutoResetEvent, that one  
> thread
> enters SyncLock block, and during that period another thread enters Sub,  
> and
> made changes in reference to Object1 causing wrong data in 1st thread?

The lack of an AutoResetEvent isn't a problem per se, but yes...

You need to synchronize access to _any_ data that could be accessed  
simultaneously by different threads.  If one thread may be trying to use  
Object1 at the same time that another thread is, that's potentially a  
problem.

In your example, if you could ensure that any time access to Object2 is  
synchronized, access to Object1 is also synchronized, that would be fine.  
For example, only ever using Object1 from within a lock on Object2.

Beware of locking on _both_ Object1 and Object2 independently, as this is  
a good way to create a deadlock situation.

Pete

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.