title: segmentation fault in iterator of std::list
body: <p>class declarations</p>
  
  <pre><code>struct cmp_str
  {
   bool operator()(char const *a, char const *b)
   {
      return std::strcmp(a, b) &lt; 0;
   }
  };
  
  class event_t {
  public:
    event_t(String *_session_time, String *_event_type, String *_table_name, String *_num_of_events);
    ~event_t();
     char *table_name;
     char *event_type;  
     pthread_mutex_t lock;
     pthread_cond_t cond;
     int num_of_events_threshold;
     double time_out; 
     int num_of_events_so_far; 
  };  
  std::map &lt;char*, std::list&lt;event_t*&gt;, cmp_str &gt; all_events;  //global map
  </code></pre>
  
  <p>I have this function which waits for a variable to reach for a certain threshold which is done through pthread_cond and pthread_mutex. It then returns. The last line gives segmentation fault.</p>
  
  <pre><code>void foo(){
      //don't worry event object ic created properly
      event_t *new_event = new event_t(args[0]-&gt;val_str(s),(args[1]-&gt;val_str(s)), (args[2]-&gt;val_str(s)), (args[3]-&gt;val_str(s)));
  
      map&lt;char*, list&lt;event_t*&gt; &gt;::iterator map_it;  
      map_it = all_events.find(new_event-&gt;table_name);
  
      if(map_it == all_events.end()){
        list&lt;event_t*&gt; *my_list = new list&lt;event_t*&gt;();
        my_list-&gt;push_back(new_event);
        all_events[new_event-&gt;table_name] = *my_list;
      }
      else{
        map_it-&gt;second.push_back(new_event);
        for (list&lt;event_t*&gt;::iterator list_it=map_it-&gt;second.begin(); list_it!=map_it-&gt;second.end(); ++list_it)
          std::cout &lt;&lt; (*list_it)-&gt;event_type &lt;&lt; " " &lt;&lt; (*list_it)-&gt;time_out &lt;&lt; " " &lt;&lt; (*list_it)-&gt;num_of_events_threshold &lt;&lt; '\n';
      }
  
  
  /*
  * waiting for number of events reach its threshold.
  */
      pthread_mutex_lock(&amp;new_event-&gt;lock);
  
      while(new_event-&gt;num_of_events_so_far &lt; new_event-&gt;num_of_events_threshold )
        pthread_cond_wait(&amp;new_event-&gt;cond, &amp;new_event-&gt;lock);
      pthread_mutex_unlock(&amp;new_event-&gt;lock);
      // segmentation fault!!!
      for (list&lt;event_t*&gt;::iterator list_it=map_it-&gt;second.begin(); list_it!=map_it-&gt;second.end(); ++list_it)
          std::cout &lt;&lt; (*list_it)-&gt;event_type &lt;&lt; " " &lt;&lt; (*list_it)-&gt;time_out &lt;&lt; " " &lt;&lt; (*list_it)-&gt;num_of_events_threshold &lt;&lt; '\n';
  }   
  </code></pre>