c# - New inside a lock -


I see the following code from my foreign programmer:

  private client [] client = New customer [0]; Public Consultants (Ant count) {lock (client) {client = new client [count]; (Int i = 0; i   

This is not the right code, but I was wondering what exactly would this do, will this method be locked on a new object every time?

To answer your question, "I was wondering what it would really do" To try

  Thread 1: Client references the context, which is the 'new customer [0]' thread 1 entered into the important block thread 1: Creates an array and assigns it to the client Reference thread 2: Locks on the client context, which is just the array created in the thread 1 thread 2 has entered important blocks   

You know that the important block has two threads at the same time . This is bad.

Comments