Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > incorrect checksum for freed object

Reply
Thread Tools

incorrect checksum for freed object

 
 
Philipp Kraus
Guest
Posts: n/a
 
      08-18-2010
Hi,

I'm to create a multithreaded algorithm and I get this runtime error message:
incorrect checksum for freed object - object was probably modified
after being freed

I use boost::thread for creating my threads. I create a some "worker"
objects (= threads) which should be solving independend a numerical
problem. The constructor of the working object gets some parameter
(const reference) and within the constructor I copy some data of the
reference into private object properties, that will be used in the
"optimize" method, which is called by the boost thread.

For testing I only write with an interator the data to std::cout from
the properties (eg the property is a std::map):
for(std::map<std::string, GiNaC::ex>::iterator it =
m_derivation.begin(); it != m_derivation.end(); ++it) {
std::cout << it->second << std::endl;
}

With one thread everything works fine, on more threads I'll get the
error message. I understand this correctly, that the message says that
several threads on another object to access and modify data there?

I would like to understand the message in that way, that I can solve my problem
Thanks for help

Phil

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      08-18-2010
On 8/18/2010 8:37 AM, Philipp Kraus wrote:
> I'm to create a multithreaded algorithm and I get this runtime error
> message:
> incorrect checksum for freed object - object was probably modified after
> being freed
> [...]
> With one thread everything works fine, on more threads I'll get the
> error message. I understand this correctly, that the message says that
> several threads on another object to access and modify data there?


The statement after the last 'that' is supposed to be complete. Let's
try to use it as a separate sentence:

"Several threads on another object to access and modify data there"

"Several threads" is the subject.
"Another object" is the object (with "on" as the preposition).

Where is the verb? Several threads WHAT on another object?

> I would like to understand the message in that way, that I can solve my
> problem


If you pass some object by reference to any threads, make sure that the
object *survives* while there is at least one thread using it. The best
approach is the reference counting. Increment the counter just before a
thread begins using the object. When the thread is done using that
object, *the thread* must decrement the reference counter. When the
counter goes to zero, the object should delete itself.

V
--
I do not respond to top-posted replies, please don't ask
 
Reply With Quote
 
 
 
 
Philipp Kraus
Guest
Posts: n/a
 
      08-18-2010
On 2010-08-18 15:53:49 +0200, Victor Bazarov said:

> On 8/18/2010 8:37 AM, Philipp Kraus wrote:
>> I'm to create a multithreaded algorithm and I get this runtime error
>> message:
>> incorrect checksum for freed object - object was probably modified after
>> being freed
>> [...]
>> With one thread everything works fine, on more threads I'll get the
>> error message. I understand this correctly, that the message says that
>> several threads on another object to access and modify data there?

>
> The statement after the last 'that' is supposed to be complete. Let's
> try to use it as a separate sentence:
>
> "Several threads on another object to access and modify data there"
>
> "Several threads" is the subject.
> "Another object" is the object (with "on" as the preposition).
>
> Where is the verb? Several threads WHAT on another object?


Sorry I'm a little bit confused

>
>> I would like to understand the message in that way, that I can solve my
>> problem

>
> If you pass some object by reference to any threads, make sure that the
> object *survives* while there is at least one thread using it. The
> best approach is the reference counting. Increment the counter just
> before a thread begins using the object. When the thread is done using
> that object, *the thread* must decrement the reference counter. When
> the counter goes to zero, the object should delete itself.


Here a code excerpt:

std::vector< worker<T,D> > l_worker;
boost::thread_group l_threadgroup;
for(std::size_t i=0; i < p_threads; ++i) {
l_worker.push_back( worker<T,D>(p_iteration, p_stepsize,
m_fulltable, m_derivation, m_optimize, m_static, p_batch) );
l_threadgroup.create_thread( boost::bind(
&worker<T,D>:ptimize, l_worker[i] ) );
}

My worker objects get parameters, which are only read in :ptimize. I
don't change the data in the parameter objects (or changes the iterator
the object?). If I copy the reference by the copy-constructor or
std::copy to a new object in my worker / thread object, I wouldn't get
the error message? My thread object throws the error message on
different runs with a different number of messages, but the numer is
less than thread count.

Thanks
Phil

 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      08-18-2010
On 8/18/2010 10:19 AM, Philipp Kraus wrote:
> On 2010-08-18 15:53:49 +0200, Victor Bazarov said:
>
>> On 8/18/2010 8:37 AM, Philipp Kraus wrote:
>>> I'm to create a multithreaded algorithm and I get this runtime error
>>> message:
>>> incorrect checksum for freed object - object was probably modified after
>>> being freed
>>> [...]
>>> With one thread everything works fine, on more threads I'll get the
>>> error message. I understand this correctly, that the message says that
>>> several threads on another object to access and modify data there?

>>
>> The statement after the last 'that' is supposed to be complete. Let's
>> try to use it as a separate sentence:
>>
>> "Several threads on another object to access and modify data there"
>>
>> "Several threads" is the subject.
>> "Another object" is the object (with "on" as the preposition).
>>
>> Where is the verb? Several threads WHAT on another object?

>
> Sorry I'm a little bit confused


Well, English can be confusing, but so can be German. And Russian.
Here everything is pretty straightforward. You just need to complete
the sentence. "Several threads" DO SOMETHING "on another object". What
do the threads do? Converge? Dance? Feed? Concentrate? Work? For
example,

I understand this correctly, that the message says that several
threads /urinate/ on another object to access and modify data there?

(I am not sure about the question mark after that statement either)

>>> I would like to understand the message in that way, that I can solve my
>>> problem

>>
>> If you pass some object by reference to any threads, make sure that
>> the object *survives* while there is at least one thread using it. The
>> best approach is the reference counting. Increment the counter just
>> before a thread begins using the object. When the thread is done using
>> that object, *the thread* must decrement the reference counter. When
>> the counter goes to zero, the object should delete itself.

>
> Here a code excerpt:
>
> std::vector< worker<T,D> > l_worker;
> boost::thread_group l_threadgroup;
> for(std::size_t i=0; i < p_threads; ++i) {
> l_worker.push_back( worker<T,D>(p_iteration, p_stepsize, m_fulltable,
> m_derivation, m_optimize, m_static, p_batch) );
> l_threadgroup.create_thread( boost::bind( &worker<T,D>:ptimize,
> l_worker[i] ) );
> }
>
> My worker objects get parameters, which are only read in :ptimize. I
> don't change the data in the parameter objects (or changes the iterator
> the object?). If I copy the reference by the copy-constructor or
> std::copy to a new object in my worker / thread object, I wouldn't get
> the error message? My thread object throws the error message on
> different runs with a different number of messages, but the numer is
> less than thread count.


The code excerpt does not contain anything that would indicate the cause
of your problem. So, two things. Your problem is not of the language
nature, it's of the Boost usage nature. As such it seems to me
off-topic here. Consider asking in Boost online forums or in
'comp.programming.threads'. And, the error message you get is from the
run-time environment. It is not from the compiler or linker. The
run-time environment belongs to your OS, and you might find it more
productive to ask about your OS in the newsgroup dedicated to your OS.

Best of luck!

V
--
I do not respond to top-posted replies, please don't ask
 
Reply With Quote
 
Philipp Kraus
Guest
Posts: n/a
 
      08-18-2010
On 2010-08-18 19:13:02 +0200, Victor Bazarov said:

> On 8/18/2010 10:19 AM, Philipp Kraus wrote:
>> On 2010-08-18 15:53:49 +0200, Victor Bazarov said:
>>
>>> On 8/18/2010 8:37 AM, Philipp Kraus wrote:
>>>> I'm to create a multithreaded algorithm and I get this runtime error
>>>> message:
>>>> incorrect checksum for freed object - object was probably modified after
>>>> being freed
>>>> [...]
>>>> With one thread everything works fine, on more threads I'll get the
>>>> error message. I understand this correctly, that the message says that
>>>> several threads on another object to access and modify data there?
>>>
>>> The statement after the last 'that' is supposed to be complete. Let's
>>> try to use it as a separate sentence:
>>>
>>> "Several threads on another object to access and modify data there"
>>>
>>> "Several threads" is the subject.
>>> "Another object" is the object (with "on" as the preposition).
>>>
>>> Where is the verb? Several threads WHAT on another object?

>>
>> Sorry I'm a little bit confused

>
> Well, English can be confusing, but so can be German. And Russian.
> Here everything is pretty straightforward. You just need to complete
> the sentence. "Several threads" DO SOMETHING "on another object".
> What do the threads do? Converge? Dance? Feed? Concentrate? Work?
> For example,
>
> I understand this correctly, that the message says that several
> threads /urinate/ on another object to access and modify data there?
>
> (I am not sure about the question mark after that statement either)
>
>>>> I would like to understand the message in that way, that I can solve my
>>>> problem
>>>
>>> If you pass some object by reference to any threads, make sure that
>>> the object *survives* while there is at least one thread using it. The
>>> best approach is the reference counting. Increment the counter just
>>> before a thread begins using the object. When the thread is done using
>>> that object, *the thread* must decrement the reference counter. When
>>> the counter goes to zero, the object should delete itself.

>>
>> Here a code excerpt:
>>
>> std::vector< worker<T,D> > l_worker;
>> boost::thread_group l_threadgroup;
>> for(std::size_t i=0; i < p_threads; ++i) {
>> l_worker.push_back( worker<T,D>(p_iteration, p_stepsize, m_fulltable,
>> m_derivation, m_optimize, m_static, p_batch) );
>> l_threadgroup.create_thread( boost::bind( &worker<T,D>:ptimize,
>> l_worker[i] ) );
>> }
>>
>> My worker objects get parameters, which are only read in :ptimize. I
>> don't change the data in the parameter objects (or changes the iterator
>> the object?). If I copy the reference by the copy-constructor or
>> std::copy to a new object in my worker / thread object, I wouldn't get
>> the error message? My thread object throws the error message on
>> different runs with a different number of messages, but the numer is
>> less than thread count.

>
> The code excerpt does not contain anything that would indicate the
> cause of your problem. So, two things. Your problem is not of the
> language nature, it's of the Boost usage nature. As such it seems to
> me off-topic here. Consider asking in Boost online forums or in
> 'comp.programming.threads'. And, the error message you get is from the
> run-time environment. It is not from the compiler or linker. The
> run-time environment belongs to your OS, and you might find it more
> productive to ask about your OS in the newsgroup dedicated to your OS.


Thanks this is for me a big hint. I think I would like to use valgrind
for debugging (but I have some compiler problems on OSX Snow Leo). The
code is cross-plattform so I can debug with valgrind under Linux and
OSX Leo.

Thanks a lot

 
Reply With Quote
 
Philipp Kraus
Guest
Posts: n/a
 
      08-18-2010
On 2010-08-18 18:40:34 +0200, Paavo Helde said:

> Philipp Kraus <(E-Mail Removed)> wrote in
> news:i4gq58$dut$(E-Mail Removed):
>
>> On 2010-08-18 15:53:49 +0200, Victor Bazarov said:
>>
>>> On 8/18/2010 8:37 AM, Philipp Kraus wrote:
>>>> I'm to create a multithreaded algorithm and I get this runtime error
>>>> message:
>>>> incorrect checksum for freed object - object was probably modified
>>>> after being freed
>>>> [...]
>>>> With one thread everything works fine, on more threads I'll get the
>>>> error message. I understand this correctly, that the message says
>>>> that several threads on another object to access and modify data
>>>> there?
>>>
>>> The statement after the last 'that' is supposed to be complete.
>>> Let's try to use it as a separate sentence:
>>>
>>> "Several threads on another object to access and modify data there"
>>>
>>> "Several threads" is the subject.
>>> "Another object" is the object (with "on" as the preposition).
>>>
>>> Where is the verb? Several threads WHAT on another object?

>>
>> Sorry I'm a little bit confused
>>
>>>
>>>> I would like to understand the message in that way, that I can solve
>>>> my problem
>>>
>>> If you pass some object by reference to any threads, make sure that
>>> the object *survives* while there is at least one thread using it.
>>> The best approach is the reference counting. Increment the counter
>>> just before a thread begins using the object. When the thread is
>>> done using that object, *the thread* must decrement the reference
>>> counter. When the counter goes to zero, the object should delete
>>> itself.

>>
>> Here a code excerpt:
>>
>> std::vector< worker<T,D> > l_worker;
>> boost::thread_group l_threadgroup;
>> for(std::size_t i=0; i < p_threads; ++i) {
>> l_worker.push_back( worker<T,D>(p_iteration, p_stepsize,
>> m_fulltable, m_derivation, m_optimize, m_static, p_batch) );
>> l_threadgroup.create_thread( boost::bind(
>> &worker<T,D>:ptimize, l_worker[i] ) );
>> }
>>
>> My worker objects get parameters, which are only read in :ptimize. I
>> don't change the data in the parameter objects (or changes the
>> iterator the object?). If I copy the reference by the copy-constructor
>> or std::copy to a new object in my worker / thread object, I wouldn't
>> get the error message? My thread object throws the error message on
>> different runs with a different number of messages, but the numer is
>> less than thread count.

>
> I suggest to run your program through valgrind with --tool=hellgrind, I'm
> sure it will catch many threading errors in the code.
>
> There is a rule that an object cannot protect against its own destruction
> in multithreaded code (no use of locking a mutex inside a destructor!), I
> wonder if you are stomping on something similar.


I have posted to the other answer and I think valgrind is a good idea.
Thanks a lot for helping

 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      08-19-2010
On Aug 18, 2:53 pm, Victor Bazarov <(E-Mail Removed)> wrote:
> On 8/18/2010 8:37 AM, Philipp Kraus wrote:


> If you pass some object by reference to any threads, make sure
> that the object *survives* while there is at least one thread
> using it. The best approach is the reference counting.


NO. Reference counting is about the worst solution here. This
is one case where single ownership is essential---if anyone can
modify the object, then it must belong to only that thread, and
no other. In fact, auto_ptr has exactly the desired semantics.
Reference counting suggests shared ownership, and shared
ownership implies race conditions.

> Increment the counter just before a thread begins using the
> object. When the thread is done using that object, *the
> thread* must decrement the reference counter. When the
> counter goes to zero, the object should delete itself.


Since only one thread may use the object at a time, there's no
need for a counter.

--
James Kanze
 
Reply With Quote
 
tni
Guest
Posts: n/a
 
      08-19-2010
On 2010-08-18 16:19, Philipp Kraus wrote:

> std::vector< worker<T,D> > l_worker;
> boost::thread_group l_threadgroup;
> for(std::size_t i=0; i < p_threads; ++i) {
> l_worker.push_back( worker<T,D>(p_iteration, p_stepsize, m_fulltable,
> m_derivation, m_optimize, m_static, p_batch) );
> l_threadgroup.create_thread( boost::bind( &worker<T,D>:ptimize,
> l_worker[i] ) );
> }


That code is likely wrong. Do you leave the scope (and automatically
destroy the l_worker vector) or do you wait for the workers to finish?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
destroy primitive/object types but memory is not freed george972@mailinator.com C Programming 5 05-25-2009 10:44 PM
A malloc error in C++ - incorrect checksum for freed object giacomomonari@email.it C++ 24 09-12-2007 12:04 AM
Detect Incorrect Checksum Rahan Cisco 3 07-27-2006 06:01 PM
incorrect checksum for freed object Une bévue Ruby 0 06-26-2006 04:21 PM
use delete to destroy primitive/object types but memory is not freed jimjim C Programming 28 04-13-2004 11:34 PM



Advertisments