.NET Threading - is lock needed for assignments

I've got some multi threaded code I'd like to increase the performace of a bit, so I'm wondering if I can get rid of a lock.

I've got a field member:

private IList<ServerStatus> status;

It's updated in a thread like so:

status = GetUpdatedStatus();

And it's used in another thread like this:

var currentStatus = status;

So the question is, can the above yield any problems without locks around the two assignment statements ?

I guess the only scenario I can see is currentStatus being null, but then again I'd expect an assignment to be somewhat thread-safe (either it has changed the reference or not)

12
задан xanatos 23 February 2011 в 06:33
поделиться