Boost logo

Threads-Devel :

Subject: [Threads-devel] shared_lock() causes Segmentation Fault in CentOS 5.5 x64?
From: Zap (zippo.fire_at_[hidden])
Date: 2011-03-14 23:57:08

Dear Pals,

I wrote a server program, and there is a class called "apInfoMutex",
which can store client's file descriptor info and what messages they sent;
the class code is as below:

class apInfoTable{
      boost::shared_mutex rwMutex;
      void   addFD(int apfd, char *srvceType, vector<string> *codeList);
      void   delFD(int apfd);
      bool   getFD(list<int> *des, char *srvceType, char *srvceCode);
      boost::unordered_map<int, boost::unordered_set<pair<string, string> > > 
      boost::unordered_map<pair<string, string>, boost::unordered_set<int> > 
there is just one apInfoTable as global declaration in my program,
but there would be two or more threads to calling these public 
method at the same time, and there is a method called "getFD()" in this class,
the code is as below:
bool apInfoTable::getFD(list<int> *des, char *type, char *code){
   bool flag=false;
   boost::shared_lock<boost::shared_mutex> lock(rwMutex);
   for(boost::unordered_set<int>::iterator it=tablePush[pair<string, string>
(type, code)].begin();it!=tablePush[pair<string, string>(type, code)].end
   return flag;
I found if I calling getFD() method like this:
char type[12];
char code[32];
list<int> fdList;
memset(type, 0x00, sizeof(type));
memset(code, 0x00, sizeof(code));
memcpy(type, "My Type", sizeof("My Type"));
memcpy(code, "My Code", sizeof("My Code"));
bool rc=getFD(&fdList, type, code);
I will got "Segmentation Fault" problem,
but if I put different parameter like this:
bool rc=getFD(&fdList, "My Type", "My Code");
or using boost::mutex instead of shared_lock() and shared_mutex in getFD(),
there wouldn't be any problem when running program.
is there any problem with my code?
or did I use shared_lock() and shared_mutex incorrectly?
P.S--I tried using unique_lock or scoped_lock instead of shared_lock(),
but there is just no any problem when I using normal boost::mutex
sincerely thanks to you

Threads-Devel list run by bdawes at, david.abrahams at, gregod at, cpdaniel at, john at