• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 585
  • Last Modified:

std::list .size method

I have seen sometimes core files in my application and when I bactraced I found it is coring at executing .size() function on std::list

std::list<std::string> myStringList

myStringList.size() sometimes cores

myStringList is member of static class which has only one instance for the entire application. I understand it should be protected by lock which I am not doing but could .size() on list ever core?
0
learningunix
Asked:
learningunix
  • 3
  • 3
1 Solution
 
Infinity08Commented:
Many things can cause a core dump given the right (or better : wrong) set of circumstances.

What kind of core dump is it ?

Is there a possibility of memory corruption ?

Since you mentioned locking, are multiple threads trying to access the list ?
0
 
learningunixAuthor Commented:
I was looking more into the code, I was having lock when I add entry to the list but when retrieving the size() I don't lock it. Could this cause the core?

Based on my design, yes it is possible one thread can update the list while I am trying to retrieve the size() of the list by other thread

Here's what I see when it execute size() on the list.

Program terminated with signal 11, Segmentation fault.
#0  0x00007f219fff95b1 in std::_List_const_iterator<string*>::operator++ (this=0x7f21ab5e8f58) at /usr/include/c++/4.3/bits/stl_list.h:221
221             _M_node = _M_node->_M_next;
(gdb) bt
#0  0x00007f219fff95b1 in std::_List_const_iterator<string*>::operator++ (this=0x7f21ab5e8f58) at /usr/include/c++/4.3/bits/stl_list.h:221
#1  0x00007f219fff95e4 in std::__distance<std::_List_const_iterator<string*> > (__first=..., __last=...) at /usr/include/c++/4.3/bits/stl_iterator_base_funcs.h:84
#2  0x00007f219fff962d in std::distance<std::_List_const_iterator<string*> > (__first=..., __last=...) at /usr/include/c++/4.3/bits/stl_iterator_base_funcs.h:119
0
 
Infinity08Commented:
>> it is possible one thread can update the list while I am trying to retrieve the size() of the list by other thread

Then that's a big suspect :)

You will need some way of ensuring this doesn't happen, and proper locking is one such way.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
learningunixAuthor Commented:
hmmm... I thought executing .size() on list is just a passive command and this should be ok. looks like my assumption is wrong
0
 
Infinity08Commented:
A std::list is a linked list. Calculating the size of a linked list is not "passive", but involves traversing all nodes in the list.
0
 
learningunixAuthor Commented:
Thanks a lot.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now