I need to know if the malloc function( and family ) implemented in Pelles IDE is thread safe?
For example; the latest GNU C ( that would be glibc-2.17 ) has a malloc implemetation that IS thread safe.
I only know that Pelles is based on LCC compiler, but searching provided not much more information or source code.
Quote from main page:
>>The compiler is originally based on LCC (by Chris Fraser and David Hanson), but since then enhanced with support for C99 and C11, a global optimizer, a new register allocator, a function inliner, intrinsic functions, and many Microsoft C extensions.<<
Thank you
The compiler is not relevant about the issue.
It depends on the crt and libraries if a function is thread safe or not.
PellesC was born from LCC, now it has been so deeply modified that doesn't remains a lot of original code. In short it is actually a completely different compiler from original LCC.
If you need the thread safe version of runtime you can select multithreaded library or DLL from the project options->compiler tab (or use directly the switches /MT or /MD on the compiler command line).
Alternatively you can link the MS runtime linking it to your code.
the most safe way is to use Win API (heap alloc and management functions) instead. I tested it in my multi-threads program with single-thread lib, no problem totally. If you use mulit-thread lib for linking, the program file size and performance would be a little bigger and lower, although it's not a key issue at the most time.
BTW never use some C functions with global varibles, such as printf/sprintf, most are in stdio.h.
Quote from: liut on October 22, 2013, 07:49:54 AM
the most safe way is to use Win API (heap alloc and management functions) instead. I tested it in my multi-threads program with single-thread lib, no problem totally. If you use mulit-thread lib for linking, the program file size and performance would be a little bigger and lower, although it's not a key issue at the most time.
BTW never use some C functions with global varibles, such as printf/sprintf, most are in stdio.h.
It is implementation defined. But all modern ones should be thread safe. I have found no problems with calling multiple printfs when testing.
I took a peek at the latest version of gnu c library and there is some mention of stream lock in there.