NO

Author Topic: Malloc thread safety in Pelles compiler  (Read 3519 times)

neo313

  • Guest
Malloc thread safety in Pelles compiler
« on: August 10, 2013, 05:27:05 PM »
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

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
Re: Malloc thread safety in Pelles compiler
« Reply #1 on: August 11, 2013, 12:38:06 PM »
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.
« Last Edit: August 11, 2013, 12:39:56 PM by frankie »
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide

liut

  • Guest
Re: Malloc thread safety in Pelles compiler
« Reply #2 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.

neo313

  • Guest
Re: Malloc thread safety in Pelles compiler
« Reply #3 on: October 24, 2013, 12:58:56 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.