title: Macro to create a uniquely named OpenMP critical section?
body: <p>Several posts explain that it is best to assign names to OpenMP <code>critical</code> sections so that their synchronizations do not conflict.
  For example, see <a href="https://stackoverflow.com/questions/19682767/critical-an-entire-function/19682797#19682797">&quot;critical&quot; an entire function</a> or <a href="https://stackoverflow.com/questions/7798010/openmp-atomic-vs-critical/7798994#7798994">openMP, atomic vs critical?</a>.</p>
  
  <p>Is it possible to define a macro to create an OpenMP critical section such that it forms a unique name each time the macro is instanced?  (Possibly this could use <code>__FILE__</code> and <code>__LINE__</code>?  However, <code>__FILE__</code> is a string?)</p>
  
  <p>Something like:</p>
  
  <pre><code>#if defined(_MSC_VER)
  #define PRAGMA(...) __pragma(__VA_ARGS__)
  #else
  #define PRAGMA(...) _Pragma(#__VA_ARGS__) // C++11
  #endif
  
  #define BEGIN_LOCK PRAGMA(omp critical (some_incantation_for_a_unique_name))
  
  BEGIN_LOCK { some_code(); }
  </code></pre>
  
  <p>And, why doesn't OpenMP make this the default behavior?  Is there some drawback to this?</p>