473,396 Members | 2,158 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,396 software developers and data experts.

Multi-threading, race conditions and managed code

Hi everyone,

If a multi-threaded .NET program creates a race condition updating a
List (for example), could this cause a memory leak/overwritten memory/
access to another objects' private memory? Basically I'd like to know
if sloppy multi-threaded code can break the CLR's guarantees of
'managed code' - garbage collection, bounds-checking, type safety etc?

First time poster, long time reader - be gentle.
Jul 1 '08 #1
2 1943
ia*******@gmail.com wrote:
If a multi-threaded .NET program creates a race condition updating a
List (for example), could this cause a memory leak/overwritten memory/
access to another objects' private memory?
Memory leak: yes, but this has nothing to do with multithreading per se.
Just because you've got garbage collection doesn't mean a program can't have
a memory leak. Garbage collection reclaims the memory of all objects that
are no longer reachable -- so indefinitely keeping references to objects is
the managed equivalent of a memory leak.
Basically I'd like to know
if sloppy multi-threaded code can break the CLR's guarantees of
'managed code' - garbage collection, bounds-checking, type safety etc?
No, no, and no, hence the "managed" part.

What can break the CLR's guarantees is unsafe code -- mucking around with
pointers and calling unmanaged functions. These actions require a full-trust
environment.

The biggest danger with multithreading is leaving objects in an inconsistent
state. This can happen because maintaining invariants under multithreading
is much harder, so it's far easier to break classes even without explicit
access to internal state.

--
J.
Jul 1 '08 #2
<ia*******@gmail.comwrote:
If a multi-threaded .NET program creates a race condition updating a
List (for example), could this cause a memory leak/overwritten memory/
access to another objects' private memory? Basically I'd like to know
if sloppy multi-threaded code can break the CLR's guarantees of
'managed code' - garbage collection, bounds-checking, type safety etc?
No, it shouldn't be able to do any of that. If you're using unsafe code
there are slightly more ways of shooting yourself in the foot, but just
threading won't have those effects. (That's not to say there aren't
weird effects that can happen, but not like that.)

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon_skeet
C# in Depth: http://csharpindepth.com
Jul 1 '08 #3

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

Similar topics

4
by: OutsiderJustice | last post by:
Hi All, I can not find any information if PHP support multi-thread (Posix thread) or not at all, can someone give out some information? Is it supported? If yes, where's the info? If no, is it...
4
by: Frank Jona | last post by:
Intellisense with C# and a multi-file assembly is not working. With VB.NET it is working. Is there a fix availible? We're using VisualStudio 2003 Regards Frank
12
by: * ProteanThread * | last post by:
but depends upon the clique: ...
2
by: google | last post by:
Hello everyone, I am having an issue using the "Multi Select" option in a list box in MS Access 2003. I am making a form that users can fill out to add an issue to the database. Each issue can...
5
by: bobwansink | last post by:
Hi, I'm relatively new to programming and I would like to create a C++ multi user program. It's for a project for school. This means I will have to write a paper about the theory too. Does anyone...
23
by: Kaz Kylheku | last post by:
I've been reading the recent cross-posted flamewar, and read Guido's article where he posits that embedding multi-line lambdas in expressions is an unsolvable puzzle. So for the last 15 minutes...
0
by: Sabri.Pllana | last post by:
We apologize if you receive multiple copies of this call for papers. *********************************************************************** 2008 International Workshop on Multi-Core Computing...
3
by: Fred | last post by:
We all agree that multi-core is where the industry is headed. Can the .NET framework take advantage of multi-cores? are the programs written in .NET multi-threaded by default or is additional...
2
by: Mirco Wahab | last post by:
After reading through some (open) Intel (CPU detection) C++ source (www.intel.com/cd/ids/developer/asmo-na/eng/276611.htm) I stumbled upon a sketchy use of multibyte characters - - - - - - - - -...
14
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
As far as I know, the C Standard has no mention of multi-threaded programming; it has no mention of how to achieve multi-threaded programming, nor does it mention whether the language or its...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
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,...
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
Oralloy
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,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.