다중 스레드 환경 관리

기술노트 95292

아키텍처:

ARM

컴포넌트:

compiler

업데이트:

2018-02-28 오전 1:46

Introduction

While using a multithreaded environment there is a need to use multithread support in the standard library, (for example calls to malloc()).

Solution

Multi thread support can be enabled in the standard library. Read the chapter: 'Enabling Multithread Support' in the Development Guide.

Verify

After implementing the system/file lock interface, it is possible to verify that the system lock functions are called when calling for example malloc/free. Just set breakpoints in the *Mtxinit, *Mtxlock and *Mtxunlock functions, and step over a call to malloc/free.

Using an RTOS

If using an RTOS, the first thing to consider is if there is a real reason to implement the multithread support.

Many RTOS vendors have already done that kind of implementation, for example:

  • Micrium uC/OS-II and III: See uC/OS-III User's Manual, chapter "Thread Safety of the Compiler’s Run-Time Library".
  • Segger embOS: See embOS CPU & Compiler specifics, chapter "Thread-safe system libraries".
  • Express Logic's ThreadX: Note that you need to define the symbol TX_ENABLE_IAR_LIBRARY_SUPPORT in both ThreadX and your application.
  • Also note that many RTOS:es recommends to use their own heap :
    • for example Freescale MQX [_mem_alloc].
    • for example Express Logic ThreadX [tx_byte/block_allocate]

Using an RTOS and C++

When using the combination of a multi-thread RTOS and C++ the compiler option

--guard_calls

needs to be used. In the IDE, the option can be specified in Project -> Options -> C/C++ Compiler -> Extra Options.

The reason is that C++ constructors/destructors could be called from several RTOS threads.

Using IAR Embedded Workbench for ARM 6.60 and newer

If using IAR Embedded Workbench for ARM version 6.60 and newer enable the linker option:

--threaded_lib

This can be done via the IDE option: Project -> Options -> General Options -> Library Configuration -> Enable thread support in the library.

Using versions 6.40 to 6.50

If using versions 6.40 or 6.50 add a number of linker options (--redirect) to Project -> Options -> Linker -> Extra Options to enable multithread support.

The --redirect options are documented in the file

<DLib_Threads.h>

Note that these options need to be added, even when using an RTOS implementation.

See the links for the DLib_Threads.h information, and an example project: Example project (version 6.50.6).zip.

 

All product names are trademarks or registered trademarks of their respective owners.

죄송하지만, 당사 사이트에서는 Internet Explorer를 지원하지 않습니다.보다 편안한 사이트를 위해 Chrome, Edge, Firefox 등과 같은 최신 브라우저를 사용해 주시길 부탁드립니다.