add mutex to make the `function_impl` thread-safe
Merge pull request #1 from AIM360/Kosta/multi_threading_fix

add mutex to make the `function_impl` thread-safe