• AVR Freaks

Hot!Is sscanf function not reentrant?

Author
SERGOSV
Starting Member
  • Total Posts : 35
  • Reward points : 0
  • Joined: 2017/11/01 11:47:58
  • Location: 0
  • Status: offline
2019/11/08 02:57:13 (permalink)
0

Is sscanf function not reentrant?

I came across the non-reentrant of the sscanf function for PIC32MZ XC32 1.44 (and 2.10 too) when called in different FreeRTOS tasks in parallel. As a result, the exeption with code 7. Corrected this by using the critical section. There is no mention in the documentation that this function is not reentrant.
Does anyone know anything about this?
Thank!!!
#1

8 Replies Related Threads

    andersm
    Super Member
    • Total Posts : 2673
    • Reward points : 0
    • Joined: 2012/10/07 14:57:44
    • Location: 0
    • Status: offline
    Re: Is sscanf function not reentrant? 2019/11/08 05:16:48 (permalink)
    +1 (1)
    You need to reverse your assumptions. If a library function is not documented as being re-entrant or threadsafe, always assume it isn't.
    #2
    SERGOSV
    Starting Member
    • Total Posts : 35
    • Reward points : 0
    • Joined: 2017/11/01 11:47:58
    • Location: 0
    • Status: offline
    Re: Is sscanf function not reentrant? 2019/11/08 07:39:29 (permalink)
    0
    Then I can not use the standard functions with FreeRTOS. Not one of them! And this is not right.
    #3
    moser
    Super Member
    • Total Posts : 519
    • Reward points : 0
    • Joined: 2015/06/16 02:53:47
    • Location: Germany
    • Status: offline
    Re: Is sscanf function not reentrant? 2019/11/08 07:59:58 (permalink)
    0
    There was a similar discussion at:
    https://www.microchip.com/forums/FindPost/1108578
     
    I think that Microchip should provide documentation about which functions are thread safe or not, or just point to the corresponding documentation for those functions oder header files, which conform to standards.
    #4
    andersm
    Super Member
    • Total Posts : 2673
    • Reward points : 0
    • Joined: 2012/10/07 14:57:44
    • Location: 0
    • Status: offline
    Re: Is sscanf function not reentrant? 2019/11/08 09:51:52 (permalink)
    +1 (1)
    If you really need reentrancy I would suggest trying Newlib instead.
    #5
    mlp
    boots too small
    • Total Posts : 825
    • Reward points : 0
    • Joined: 2012/09/10 15:12:07
    • Location: previously Microchip XC8 team
    • Status: offline
    Re: Is sscanf function not reentrant? 2019/11/08 11:20:56 (permalink)
    +2 (2)
    moser
    I think that Microchip should provide documentation about which functions are thread safe or not, or just point to the corresponding documentation for those functions oder header files, which conform to standards.

    As far as I'm aware the XC compilers and their libraries are documented to conform to the C90 and C99 standards. The C language defined in those standards does not include any notion of "threads", and thus your request is satisfied by the language's underlying concept of Undefined Behaviour if you do something not explicitly permitted by the standard.

    Mark (this opinion available for hire)
    #6
    Link
    Junior Member
    • Total Posts : 91
    • Reward points : 0
    • Joined: 2003/11/07 12:48:40
    • Location: Leeds, UK
    • Status: offline
    Re: Is sscanf function not reentrant? 2019/11/08 13:07:07 (permalink)
    0
    Indeed. You would need a compiler for the 'OS' itself to have any expectancy of things such as threading, etc. Libraries or roll your own.
    #7
    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11423
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: Is sscanf function not reentrant? 2019/11/08 13:47:29 (permalink)
    +2 (2)
    The C standard says,
     
    The functions in the standard library are not guaranteed to be reentrant and may modify objects with static storage duration.



    #8
    sborden
    Super Member
    • Total Posts : 1951
    • Reward points : 0
    • Joined: 2010/08/05 02:12:53
    • Location: 0
    • Status: offline
    Re: Is sscanf function not reentrant? 2019/11/26 04:43:41 (permalink)
    0
    The standard C libraries are typically not used in real time applications. You can roll your own, run them only within the context of 1 thread, or get "thread safe" versions. FreeRTOS has dealt with this many times and clearly warns about it. Some posts that have arisen on the subject:
     
    https://www.freertos.org/FreeRTOS_Support_Forum_Archive/November_2015/freertos_sprintf_in_FreeRTOS_76ff6992j.html
     
    https://www.freertos.org/FreeRTOS_Support_Forum_Archive/March_2014/freertos_Problem_Scanf_59f5f696j.html
     
    https://mcuoneclipse.com/2017/07/02/using-freertos-with-newlib-and-newlib-nano/
     
     
    #9
    Jump to:
    © 2019 APG vNext Commercial Version 4.5