Sinhronisation of allocation and freeing of memory
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.
Re: Sinhronisation of allocation and freeing of memory
Something you did elsewhere probably corrupted the heap.
Re: Sinhronisation of allocation and freeing of memory
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.
Re: Sinhronisation of allocation and freeing of memory
Quote:
Originally Posted by
Arjay
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.
Re: Sinhronisation of allocation and freeing of memory
Quote:
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?
Re: Sinhronisation of allocation and freeing of memory
Quote:
Originally Posted by
JVene
What is the OS and the compiler?
I uses VC++ 6.0 on Windows XP x32
Quote:
Originally Posted by
JVene
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?
Quote:
Originally Posted by
JVene
Does you build crash on the very first new?
No, I have crash in many places of allocation or deallocation of memory.
Quote:
Originally Posted by
JVene
Care to post any code for more specific help than generalizations?
I can't post any part of sources, because I develop comercial product.
Re: Sinhronisation of allocation and freeing of memory
Without posting code, it doesn't leave much for us to go on.
Try looking for unitialized variables.
Re: Sinhronisation of allocation and freeing of memory
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.
Re: Sinhronisation of allocation and freeing of memory
I found the problem, there was "static" variables inside functions.
Re: Sinhronisation of allocation and freeing of memory