views:

42

answers:

1

Sometimes I see the term "free-threaded" to describe a class or a method. It seems to have a similar or identical meaning to "thread-safe".

Is there a difference between the two terms?

+2  A: 

There may well be other things meant in other contexts, but in cases I've worked with in the past, "free threaded" means it works, or at least can work, across different threads without any marshalling between apartments.

Apartment-threading in contrast blocks off different "apartments" with separate copies of "global" data (which hence isn't really global, when you think about it) and either allows only one thread to operate in the apartment, or allows several but which will still be separate from those using other apartments.

Now, because the apartment model offers some thread-safety of its own, some (but not all) concerns about thread-safety go away. A piece of code that is designed to operate in an apartment model will be thread-safe, but some or all of that thread-safety is coming from the apartment model.

A free threaded piece of code will have to provide full guarantees of whatever degree of thread-safety it is claiming itself.

Which means it pretty much does mean the same thing as thread-safe, for any intents and purposes where you don't also have to consider the thread-safety of the use of apartment-model code.

Jon Hanna
Ah! And COM is making heavy use of this "apartment" idea. I just realized that whenever I stumbled over "free-threaded" (DirectX for example), there was COM involved. The term is possibly not used elsewere. As long as my stuff does not involve COM, I'll just use "thread-safe". Thanks a lot!
Lawnmower
Yes, I know it from when I used to work with COM.
Jon Hanna