Thread safe for malloc

Included pthread.h & malloc() protected with pthread_mutex_lock()/
pthread_mutex_unlock() block
Thread-safe

Implementation of thread-safe