title: making this function thread safe while maintaining recursivity
body: <p>How do I make this function thread safe while maintaining the recursive nature of the code?</p>
  
  <pre><code>int foo(char *p)
   {
    static int i = 0;
     if (*p == '\0') return i;
     i++;
   return foo(p+1);
  }
  </code></pre>