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 / Windows Forms / Drawing / May 2004

Tip: Looking for answers? Try searching our database.

Thread safety

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steve McLellan - 27 May 2004 00:24 GMT
Hi,

I've just discovered that accessing Image.Height (and probably other
properties) in a multi-threaded environment can cause access problems (as a
test, you can spawn a hundred threads and get them all to perform a couple
of multiplications on an image's height and width ). I know I can prevent
simultaneous access, but is there any reason why Image can't be accessed
like this? And is this common for all .NET objects? I know the docs say 'not
thread-safe' but not being safe for multiple reads seems bizarre.

Steve
Justin Rogers - 27 May 2004 00:34 GMT
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdicpp/GDIPlus/
sec_gdiplus.asp?frame=true


Info on thread safety.  Internally Height always calls methods to get the height
and no caching is performed.  Since each call is a method, there might be some
work, the return of an ObjectBusy status, or any number of other items that
might go wrong.

Signature

Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

> Hi,
>
[quoted text clipped - 7 lines]
>
> Steve
Steve McLellan - 27 May 2004 00:43 GMT
OK, cheers. Just the sort of thing I need to find out at 1am :-)  Is this
common to the framework? I'm never likely to know what's cached and what
isn't for a given property.... and surely this is unnecessary if there are
only read operations going on? I'm still not sure why exactly that could
ever be a problem.

Steve

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdicpp/GDIPlus/
sec_gdiplus.asp?frame=true


> Info on thread safety.  Internally Height always calls methods to get the height
> and no caching is performed.  Since each call is a method, there might be some
[quoted text clipped - 12 lines]
> >
> > Steve
Justin Rogers - 27 May 2004 00:51 GMT
Image is abstracting you from a bunch of method calls.  In GDI+ each object
is simply a pointer or handle, and you call methods to get the information from
those handles.  If Image cached the values for you, then it would have a bunch
of state work to handle for things like moving to the next frame or other events
that could possibly change the height or width of the underlying image.

This generally isn't a huge problem across the framework, but is common when
API's are created that are wrapping an unmanaged API.  The unmanaged API's
simply have semantics that don't translate 1 for 1 into the .NET world.

Signature

Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

> OK, cheers. Just the sort of thing I need to find out at 1am :-)  Is this
> common to the framework? I'm never likely to know what's cached and what
[quoted text clipped - 3 lines]
>
> Steve

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdicpp/GDIPlus/
sec_gdiplus.asp?frame=true


> > Info on thread safety.  Internally Height always calls methods to get the
> height
[quoted text clipped - 19 lines]
> > >
> > > Steve
Steve McLellan - 27 May 2004 01:07 GMT
Splendid explanation. That does kind of make sense, and it's a good job we
spotted it now (and didn't put it into our 'strange but true' bug file) and
not after release. My TV show "When multithreading goes bad" is coming on
leaps and bounds.

Thanks again, and I hope it's not as late where you are as it is here :-)

Steve

> Image is abstracting you from a bunch of method calls.  In GDI+ each object
> is simply a pointer or handle, and you call methods to get the information from
[quoted text clipped - 13 lines]
> >
> > Steve

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdicpp/GDIPlus/
sec_gdiplus.asp?frame=true


> > > Info on thread safety.  Internally Height always calls methods to get the
> > height
[quoted text clipped - 19 lines]
> > > >
> > > > Steve

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.