Actions

icon Post
text/html Subscribe
text/html Unsubscribe

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [arm-gnu] Sourcery G++ for bare-metal ARM and thread-safety on RTOS


  • To: Andreas Messerschmid <amesserschmid@xxxxxxx>
  • Subject: Re: [arm-gnu] Sourcery G++ for bare-metal ARM and thread-safety on RTOS
  • From: Carlos O'Donell <carlos@xxxxxxxxxxxxxxxx>
  • Date: Wed, 05 Nov 2008 10:14:35 -0500

Andreas Messerschmid wrote:
I'm using a multi-threaded RTOS on an ARM machine with the Sourcery G++
bare-metal toolchain and I want to set up a multi-threaded C++ project.
Are the C++ standard libs thread-safe and reentrant ? What about the
heap / new and delete ? Is there any other way to protect the heap from
getting corrupted by several simultaneous multi-thread accesses than
globally overloading new and delete ?

Reentrancy in newlib is provided by the RTOS, the RTOS provides reentrant low-level implementations of several key functions e.g. _open_r (reentrant version of open). All higher-level reentrant functions use these low-level reentrant functions to provide reentrancy. Please read Chapter 10 "Reentrancy" in the Newlib C Library manual. CodeSourcery provides the documentation in PDF form to all of our subscription customers.

The newlib memory allocation routines are thread safe, but require the RTOS to provide the locking primitives. Please see Chapter 2, Section 24, page 28, "__malloc_lock, __malloc_unlock - lock malloc pool". Similarly defined are __tz_lock/__tz_unlock and __env_lock/__env_unlock. The Newlib C library lock API is defined in sys/lock.h

I hope that helps point you in the right direction.

Cheers,
Carlos.
--
Carlos O'Donell
CodeSourcery
carlos@xxxxxxxxxxxxxxxx
(650) 331-3385 x716