Scott M. wrote:
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:
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
);
}
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>