Re: Class and Multi-thread safety
- From: Nuno Magalhaes <nunommagalhaes@xxxxxxxxxxx>
- Date: Tue, 16 Oct 2007 12:32:55 -0700
On 16 Out, 19:25, Jon Skeet [C# MVP] <sk...@xxxxxxxxx> wrote:
Nuno Magalhaes <nunommagalh...@xxxxxxxxxxx> wrote:
Is there any keyword applicable to a class to make it thread-safe?
Without having to put lock(this){} in all functions?
Putting lock(this) doesn't make it thread-safe.
Thread safety is not a simple matter - you need to carefully consider
threading and various issues when making a class thread-safe. In
particular, think about any code in other classes you call while
holding a lock - if you're not careful, you can easily deadlock.
I'd also recommend against locking on "this" to start with.
--
Jon Skeet - <sk...@xxxxxxxxx>http://www.pobox.com/~skeet Blog:http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
What is the difference between locking on "this" and locking on an
object inside the class? My object is never changed. What can go wrong?
.
- Follow-Ups:
- Re: Class and Multi-thread safety
- From: Mads Bondo Dydensborg
- Re: Class and Multi-thread safety
- From: Jon Skeet [C# MVP]
- Re: Class and Multi-thread safety
- References:
- Class and Multi-thread safety
- From: Nuno Magalhaes
- Re: Class and Multi-thread safety
- From: Jon Skeet [C# MVP]
- Class and Multi-thread safety
- Prev by Date: Re: App. crashes on assigning arraylist to DataGridView datasource
- Next by Date: RE: ASP, ASP.net, and C#
- Previous by thread: Re: Class and Multi-thread safety
- Next by thread: Re: Class and Multi-thread safety
- Index(es):
Relevant Pages
|
Loading