title: Free memory atomically
body: <p>This is a function, I am using to free dynamically allocated memory</p>
  
  <pre><code>void Free(void* arg) {
      if(arg!=NULL) {
          free(arg);
          arg=NULL;
      }
  }
  </code></pre>
  
  <p>So far it was working fine, until I started using pthreads. From time to time my stack is being smashed, and the only thing I can do is to use pthread_mutex_lock()
  <br/>Is there any atomic bulletin to check&amp;free memory in gcc?<br/>Or may be you can present another solution? I hope that mutex is not the only way to do that</p>