Click to See Complete Forum and Search --> : Sinhronisation of allocation and freeing of memory
Gastello
July 21st, 2009, 11:51 AM
I've got a problem with sinhronisation of a function which is called from several threads. The function do no use static variables. And there is no connection variables between threads. In debuger the aplication crashes on new or delete operators inside the function. In internet I've read that these operators are already synhronized. Please help me to find solution of the problem.
Lindley
July 21st, 2009, 12:32 PM
Something you did elsewhere probably corrupted the heap.
Arjay
July 21st, 2009, 03:06 PM
If the functions access data other than local variables within the function, then access to this data must be synchronized. This data could be global data, or data within a dll, or any other form of shared data.
Gastello
July 22nd, 2009, 06:01 AM
If the functions access data other than local variables within the function, then access to this data must be synchronized. This data could be global data, or data within a dll, or any other form of shared data.
There is on shared variables, functions working separately. The heap allocation data is not synchronized. But as I read in Internet - operator new and delete should be sinhronized.
JVene
July 22nd, 2009, 07:48 AM
And there is no connection variables between threads. In debuger the aplication crashes on new or delete operators inside the function.
What is the OS and the compiler?
Are you certain you've selected the appropriate multi-threaded runtime library? (I'd assume you'd have trouble launching threads otherwise, but I suppose it is still possible).
You're correct that new/delete are synchronized (one might go so far as to say serialized).
If you're certain without doubt that not one single byte of data is shared between threads, there's not problem running without further synchronization against mutexes/critical sections/etc.
Does you build crash on the very first new?
Care to post any code for more specific help than generalizations?
Gastello
July 22nd, 2009, 10:56 AM
What is the OS and the compiler?
I uses VC++ 6.0 on Windows XP x32
Are you certain you've selected the appropriate multi-threaded runtime library? (I'd assume you'd have trouble launching threads otherwise, but I suppose it is still possible).
I have defined in settings page "Code generation" "Use run-time library" as "Debug Multithreaded DLL" for debug and for realize "Multithreaded DLL". Do you mean this?
Does you build crash on the very first new?
No, I have crash in many places of allocation or deallocation of memory.
Care to post any code for more specific help than generalizations?
I can't post any part of sources, because I develop comercial product.
Arjay
July 22nd, 2009, 11:24 AM
Without posting code, it doesn't leave much for us to go on.
Try looking for unitialized variables.
mikoil
July 25th, 2009, 08:35 PM
Or, check for buffer overrun - maybe you do something like this:
char *szName = new char[100];
sprintf(szName, ....);
And the sprintf() function writes more than 100 chars. That's also why you get random crashes.
Gastello
July 27th, 2009, 05:27 AM
I found the problem, there was "static" variables inside functions.
JVene
July 27th, 2009, 02:42 PM
Ah, glad you found that.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.