title: Any issues with large numbers of critical sections?
body: <p>I have a large array of structures, like this:</p>
  
  <pre><code>typedef struct
  {
      int a;
      int b;
      int c;
      etc...
  }
  data_type;
  
  data_type data[100000];
  </code></pre>
  
  <p>I have a bunch of separate threads, each of which will want to make alterations to elements within data[]. I need to make sure that no to threads attempt to access the same data element at the same time. To be precise: one thread performing data[475].a = 3; and another thread performing data[475].b = 7; at the same time is not allowed, but one thread performing data[475].a = 3; while another thread performs data[476].a = 7; is allowed. The program is <em>highly</em> speed critical. My plan is to make a separate critical section for each data element like so:</p>
  
  <pre><code>typedef struct
  {
      CRITICAL_SECTION critsec;
      int a;
      int b;
      int c;
      etc...
  }
  data_type;
  </code></pre>
  
  <p>In one way I guess it should all work and I should have no real questions, but not having had much experience in multithreaded programming I am just feeling a little uneasy about having so many critical sections. I'm wondering if the sheer number of them could be creating some sort of inefficiency. I'm also wondering if perhaps some other multithreading technique could be faster? Should I just relax and go ahead with plan A?</p>