Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newlib/Send string over UART with multiple threads cuts string of thread with lower priority #10495

Closed
biboc opened this issue Nov 28, 2018 · 4 comments
Assignees
Labels
Area: drivers Area: Device drivers Area: network Area: Networking State: stale State: The issue / PR has no activity for >185 days

Comments

@biboc
Copy link
Member

biboc commented Nov 28, 2018

Description

If two threads with different priorities try to write a string over UART using Ethos, the string of thread with lower priority will be cut.

[EDIT]
As I show below with uart-thread-mutex_pb_simple, the problem does not come from Ethos.
If you enable mutex in main.c, output is good. If you use only mutex in stdio_uart.c, string are cut.
Between these two calls, it is newlib? Am I right?

Is newlib and printf thread safe?

Steps to reproduce the issue

Checkout my branch: https://github.com/biboc/RIOT/tree/uart_mutex_thread_pb
And run example uart-thread-mutex_pb_BR on samr21-xpro (make flash BOARD=samr21-xpro)
OR
Run example uart-thread-mutex_pb_simple on samr21-xpro (make flash BOARD=samr21-xpro)

My problem first appeared on STM32F4 as a Border Router, I didn't try the example above on this board but it should behave the same.

Expected results

The string of thread with lower priority should be fully printed before other thread can print string

Actual results

Output from example uart-thread-mutex_pb_BR :

2018-11-28 11:58:50.71 ~~33     `@0909]!UHCP@~~}!main(): This is RIOT!
(Version: 2018.10-RC1-330-gd8cfe-uart_mutex_thread_pb)
2018-11-28 11:58:50.71 ~~}!RIOT border router example application
2018-11-28 11:58:50.72 ~~}!THREAD 2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+
2018-11-28 11:58:50.74 ~~}!THREAD 2-|+2-|+2-|+2-|+THREAD
1_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*1
2018-11-28 11:58:50.75
~~}!2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+
2018-11-28 11:58:50.76 ~~}!THREAD
2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+

Output from example uart-thread-mutex_pb_simple :

main(): This is RIOT! (Version: 2018.10-RC1-330-gd8cfe)
RIOT border router example application
THREAD 2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+2-|+
THREAD 2-|+2-|+2-|+2-11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*1
THREAD 1_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*11_!*1

Versions

Ubuntu 16.04 and RIOT master (28/11/2018)

@biboc biboc added Area: network Area: Networking Area: drivers Area: Device drivers labels Nov 28, 2018
@biboc biboc changed the title Ethos/Send string with multiple threads breaks string of thread with lower priority Newlib/Send string over UART with multiple threads cuts string of thread with lower priority Nov 28, 2018
@kaspar030
Copy link
Contributor

Newlib is not thread-safe. Could you try merging #8619?

@biboc
Copy link
Member Author

biboc commented Nov 28, 2018

#8619 Will try to merge

Do you have a list of functions that are not thread safe?
Are va_start, va_end and vsnprintf thread safe?

@biboc
Copy link
Member Author

biboc commented Nov 29, 2018

@kaspar030, could I replace printf newlib function by another which is thread safe? Is is possible with newlib?

@stale
Copy link

stale bot commented Aug 10, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions.

@stale stale bot added the State: stale State: The issue / PR has no activity for >185 days label Aug 10, 2019
@stale stale bot closed this as completed Sep 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: drivers Area: Device drivers Area: network Area: Networking State: stale State: The issue / PR has no activity for >185 days
Projects
None yet
Development

No branches or pull requests

3 participants