|
-
July 21st, 2009, 11:51 AM
#1
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.
-
July 21st, 2009, 12:32 PM
#2
Re: Sinhronisation of allocation and freeing of memory
Something you did elsewhere probably corrupted the heap.
-
July 21st, 2009, 03:06 PM
#3
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.
-
July 22nd, 2009, 06:01 AM
#4
Re: Sinhronisation of allocation and freeing of memory
 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.
-
July 22nd, 2009, 07:48 AM
#5
Re: Sinhronisation of allocation and freeing of memory
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?
If my post was interesting or helpful, perhaps you would consider clicking the 'rate this post' to let me know (middle icon of the group in the upper right of the post).
-
July 22nd, 2009, 10:56 AM
#6
Re: Sinhronisation of allocation and freeing of memory
 Originally Posted by JVene
What is the OS and the compiler?
I uses VC++ 6.0 on Windows XP x32
 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?
 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.
 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.
-
July 22nd, 2009, 11:24 AM
#7
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.
-
July 25th, 2009, 08:35 PM
#8
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.
-
July 27th, 2009, 05:27 AM
#9
Re: Sinhronisation of allocation and freeing of memory
I found the problem, there was "static" variables inside functions.
-
July 27th, 2009, 02:42 PM
#10
Re: Sinhronisation of allocation and freeing of memory
If my post was interesting or helpful, perhaps you would consider clicking the 'rate this post' to let me know (middle icon of the group in the upper right of the post).
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|