Mutex locking using temporory objects instead of set_pre_string and '\n'