Is printf thread safe ?

Is printf thread safe ?

Home Forums Real-Time Kernels Is printf thread safe ?

This topic contains 1 reply, has 2 voices, and was last updated by  Matt Gordon 3 years ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #18451

    chhs pai

    I am studying Micrium_RM48xHDK_os3-fs-sd-no-src from Download Center.
    Why was App_SerPrintf replaced by printf ?
    Is printf thread safe ?



    Matt Gordon

    App_SerPrintf() is a function added to many of Micrium’s example projects in order to allow application code to output helpful messages to users. As this function is considered to be example code, and not core Micrium software, it is typically not subject to the same level of scrutiny and testing as, say, a µC/OS-III API function. In most environments, a relatively simple way for Micrium’s developers to implement App_SerPrintf() is with the standard library function printf().

    Of course, the fact that App_SerPrintf() lies outside of Micrium’s core modules does not mean that any thread-safety issues the function might impose can be completely ignored, so the question of whether or not printf() is safe for multi-task systems is still an important one, and the short answer to this question is “no.” Generally speaking, application developers cannot assume that the printf() implementation provided with their development environment will operate without problems in the presence of multi-tasking. However, this rule does not hold for all printf() implementations and all multi-tasking systems.

    For developers whose multi-task application code is based on one of Micrium’s kernels—µC/OS-II and µC/OS-III—there are actually several safe options for printf(). That’s because Micrium has worked with tool-chain providers, including IAR, to develop interface code that helps library functions safely manage resources in a multi-task environment. With this code included in a Micrium-based project, an application can invoke printf() (or any other standard library routine) without the possibility for data corruption that otherwise accompanies library calls. Further details on the measures that must be taken to make library calls safe for multi-task environments can be found in Micrium’s online documentation.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

View the complete site map