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 / April 2006

Tip: Looking for answers? Try searching our database.

Type-Safe / Thread-Safe

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Scott M. - 18 Apr 2006 15:37 GMT
Can someone explain the two terms "type-safe" and "thread-safe"?  I
understand what a type and a thread are, but what does it mean for them to
be "safe"?
Larry Lard - 18 Apr 2006 17:07 GMT
> Can someone explain the two terms "type-safe" and "thread-safe"?  I
> understand what a type and a thread are, but what does it mean for them to
> be "safe"?

Note that these terms are differently applicable; type safety is a
property of languages, whereas thread safety is a property of
particular pieces of code. The wikipedia entries look OK for both:

<http://en.wikipedia.org/wiki/Type_safety>

<http://en.wikipedia.org/wiki/Thread_safety>

Signature

Larry Lard
Replies to group please

Nick Hounsome - 18 Apr 2006 17:47 GMT
>> Can someone explain the two terms "type-safe" and "thread-safe"?  I
>> understand what a type and a thread are, but what does it mean for them
[quoted text clipped - 4 lines]
> property of languages, whereas thread safety is a property of
> particular pieces of code. The wikipedia entries look OK for both:

I think that that is slightly over simplistic.
As the wiki says - type safety can be enforced at compile time or at
runtime. C# is type safe because the runtime will not permit invalid type
casting, however compile time type safety is obviously safer in than runtime
type safety and from this you can expand the definition of typesafety to
include coding. The obvious examples are the collections:

An ArrayList intended to hold ints is type-safe only in the sense that
nothing in it can be treated as an int unless it actually is one. It is not
type-safe in that there is nothing to stop someone putting a string in it.

List<int> is type-safe in a much stronger sense because it is type-safe at
compile time rather than runtime and yet this due to the particular class
rather than the language.

> <http://en.wikipedia.org/wiki/Type_safety>

Similarly there are gradations of thread-safety.
A method may be thread safe whereas a way of using it is not.
The classic example is:

for(i=0; i< list.Length; ++i)
{
   doStuff(list[i]);
}

This would not normally be considered thread-safe regardless of whether or
not the Length property and the indexer are thread-safe.

> <http://en.wikipedia.org/wiki/Thread_safety>
Scott M. - 18 Apr 2006 18:04 GMT
So, in VB.NET, if you had Option Strict turned on (which prevents late
binding and implicit casts), would VB.NET then be considered Type-Safe?

>>> Can someone explain the two terms "type-safe" and "thread-safe"?  I
>>> understand what a type and a thread are, but what does it mean for them
[quoted text clipped - 36 lines]
>
>> <http://en.wikipedia.org/wiki/Thread_safety>
Michael D. Ober - 18 Apr 2006 18:19 GMT

Yes - for the most part - especially if you are using VB 2005.  VB, and the
rest of .NET, contains the "Object" type which can contain any type.
However, to do anything with it, you must explicitely cast it to a different
type at runtime.  In VB 2005, this is done via the CType(myOjb, <target
type>).  Note that this cast can fail with an exception.

Mike.

> So, in VB.NET, if you had Option Strict turned on (which prevents late
> binding and implicit casts), would VB.NET then be considered Type-Safe?
[quoted text clipped - 39 lines]
> >
> >> <http://en.wikipedia.org/wiki/Thread_safety>
Scott M. - 18 Apr 2006 20:53 GMT
How is that different than VB.NET 2003?  In 2003, we use CType(sourceObj,
targetType) and DirectCast(Type, targetType).  With Option Strict turned on,
both should flag errors at compile time.

> Yes - for the most part - especially if you are using VB 2005.  VB, and
> the
[quoted text clipped - 55 lines]
>> >
>> >> <http://en.wikipedia.org/wiki/Thread_safety>
Michael D. Ober - 18 Apr 2006 17:48 GMT

Type-Safe refers to the language's ability to prevent you from doing
something like this:

dim s as string
dim i as integer

s = "My String"
i = s

Preferably, this protection is done at compile time and not at run time.

Thread-Safe refers to objects and methods in those objects being protected
from internal corruption when multiple execution threads simultaneously
update the object (or update while reading).  These types of errors can be
extremely hard to troubleshoot.

Mike Ober.

> Can someone explain the two terms "type-safe" and "thread-safe"?  I
> understand what a type and a thread are, but what does it mean for them to
> be "safe"?

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.