Re: Class and Multi-thread safety
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Tue, 16 Oct 2007 19:25:51 +0100
Nuno Magalhaes <nunommagalhaes@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 - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.
- Follow-Ups:
- Re: Class and Multi-thread safety
- From: Nuno Magalhaes
- Re: Class and Multi-thread safety
- References:
- Class and Multi-thread safety
- From: Nuno Magalhaes
- Class and Multi-thread safety
- Prev by Date: Re: Assigning "this"
- Next by Date: Re: Performance Issues with Delegates
- Previous by thread: Class and Multi-thread safety
- Next by thread: Re: Class and Multi-thread safety
- Index(es):
Relevant Pages
|