title: multithreading with calling the same function
body: <p>I come up with this question that was asked to write a code in C++. So, I need to use the C++ synchronization primitives. </p>
  
  <p>Q: Create a method (e.g. foo) which accept a integer as a argument and print on console. This method is accessed by multiple threads. If two or more threads call the method with same value then only one thread should allow to print the value other threads should wait. If values are different then all threads should allow to print the value.</p>
  
  <p>My suggestion is using a global hashtable lets say, unordered_map(i, semaphore) map. So, when foo(i) is called, foo checks the hashtable. If i is not in the hashtable, we add map[i]=semaphore(0). When i printed, map[i].release() is called to allow other waiting threads with input i continue their print operation. On the other hand, if i is already in the hash, it means that other thread with the same input is running, so it should wait via map[i].aquire(). </p>
  
  <p>Hope you could help me to find a better solution or a corrected version of this proposal.  </p>