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 4 1978 http://msdn.microsoft.com/library/de...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.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers
"Steve McLellan" <sjm.NOSPAM AT fixerlabs DOT com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. .. 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
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
"Justin Rogers" <Ju****@games4d otnet.com> wrote in message
news:e5******** ******@tk2msftn gp13.phx.gbl... http://msdn.microsoft.com/library/de...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.
-- Justin Rogers DigiTec Web Consultants, LLC. Blog: http://weblogs.asp.net/justin_rogers
"Steve McLellan" <sjm.NOSPAM AT fixerlabs DOT com> wrote in message news:%2******** ********@TK2MSF TNGP12.phx.gbl. .. 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
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.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers
"Steve McLellan" <sjm.NOSPAM AT fixerlabs DOT com> wrote in message
news:Ob******** ******@TK2MSFTN GP09.phx.gbl... 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
"Justin Rogers" <Ju****@games4d otnet.com> wrote in message news:e5******** ******@tk2msftn gp13.phx.gbl... http://msdn.microsoft.com/library/de...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.
-- Justin Rogers DigiTec Web Consultants, LLC. Blog: http://weblogs.asp.net/justin_rogers
"Steve McLellan" <sjm.NOSPAM AT fixerlabs DOT com> wrote in message news:%2******** ********@TK2MSF TNGP12.phx.gbl. .. 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
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
"Justin Rogers" <Ju****@games4d otnet.com> wrote in message
news:OC******** *****@TK2MSFTNG P12.phx.gbl... 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.
-- Justin Rogers DigiTec Web Consultants, LLC. Blog: http://weblogs.asp.net/justin_rogers
"Steve McLellan" <sjm.NOSPAM AT fixerlabs DOT com> wrote in message news:Ob******** ******@TK2MSFTN GP09.phx.gbl... 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
"Justin Rogers" <Ju****@games4d otnet.com> wrote in message news:e5******** ******@tk2msftn gp13.phx.gbl...
http://msdn.microsoft.com/library/de...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.
-- Justin Rogers DigiTec Web Consultants, LLC. Blog: http://weblogs.asp.net/justin_rogers
"Steve McLellan" <sjm.NOSPAM AT fixerlabs DOT com> wrote in message news:%2******** ********@TK2MSF TNGP12.phx.gbl. .. > 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 > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jonathan Burd |
last post by:
Greetings everyone,
Here is a random string generator I wrote for an application
and I'm wondering about the thread-safety of this function.
I was told using static and global variables cause
potential problems for thread-safety. So far, I'm only confused.
I need a proper explanation for the concept so I can understand how
to write...
|
by: Alexander Fleck |
last post by:
Hi,
I' ve to make a software module thread safe.
I know how to realize that and what' re the main topics of thread safety.
But I don' t know how thread safety can be tested. I read about a test for web servers. These apps' re tested with a stress test. That doesn' t work for my module. I searched the web but didn' t find a solution that...
|
by: The Crow |
last post by:
for example i have static readonly SqlParameter and i want to clone them at
runtime. as clone operation will not write to SqlParameter object, just
reading, should i lock that object during read operations?
|
by: Brett |
last post by:
I have a second thread, t2, that errors out and will stop. It's status is
then "Stopped". I try to start t2 from thread 1, t1, by checking
If t2.threadstate = "Stopped" Then
t2.start()
However, this throws and error:
System.Threading.ThreadStateException: Thread is running or terminated; it
can not restart.
|
by: Warren Sirota |
last post by:
Hi,
I've got a method that I want to execute in a multithreaded environment
(it's a specialized spider. I want to run a whole bunch of copies at low
priority as a service). It works well running as a single application.
I was wondering if there is a "Thread-Safety Analysis Wizard"?
I'm sure I'm grossly off-base with the following, so...
| |
by: fniles |
last post by:
I am using VB.NET 2003 and a socket control to receive and sending data to
clients.
As I receive data in 1 thread, I put it into an arraylist, and then I remove
the data from arraylist and send it to the client.
Before adding data to the arraylist, I check if the depth of the arraylist
is longer than iMaxQueueDepth, and if it is, I clear the...
|
by: paul.hester |
last post by:
Hi all,
All of the classes in my DAL are static, with constants defining the
stored procedures and parameters. I've been having some problems with
my site which makes me wonder if there's a thread safety issue.
Are consts thread safe? Would the following example create any thread
safety issues? Would you recommend using static readonly...
|
by: arun.darra |
last post by:
Are the following thread safe:
1. Assuming Object is any simple object
Object* fn()
{
Object *p = new Object();
return p;
}
2. is return by value thread safe?
|
by: Graham Wideman |
last post by:
Folks:
Can anyone tell me what controls php's "thread safety" feature?
I have an installation where phpinfo() is showing Thread safety: enabled,
whereas I need it disabled in order to work with xdebug.so.
So far as I can tell, the options I used to configure php did not ask for
thread-safety, and I also don't see any options to...
|
by: Henri.Chinasque |
last post by:
Hi all,
I am wondering about thread safety and member variables. If I have
such a class:
class foo {
private float m_floater = 0.0;
public void bar(){
m_floater = true;
}
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |