I was using pthread_mutex_t
s beforehand. The code sometimes got stuck. I had a couple of lines of code scattered across functions that I wrapped...
pthread_mutex_lock(&map_mutex);// Line 1
//critical code involving reading/writing wrapped around a mutex //Line 2
pthread_mutex_unlock(&map_mutex); //Line 3
Not sure how/where the code was getting stuck, I switched the pthread_mutex_t
to a boost:mutex
1) If i just substitute lines 1 and 3 with boost::lock_guard<boost::mutex> lock(map_mutex);
in line 1, and everything works flawlessly, what could be going wrong with the pthread implementation?
2) Am I giving up performance by switching to boost. The critical portion here is very time-sensitive so I would like the mutex to be very lightweight. (C++, redhat)