Mbed-os: Tickers update should be atomic

Created on 12 Jan 2018  路  5Comments  路  Source: ARMmbed/mbed-os

Description

  • Type: Bug

Bug

The function updating the current ticker value does not do it atomically, as a result concurrent updates of the ticker may corrupt the ticker value. This may happen if multiples thread read concurrently the ticker value.

Protecting the data structure from concurrent updates with a critical section may be a solution.

hal bug

Most helpful comment

I've just patched this across to my build and initial impressions are that it has fixed the issue. Thanks!

All 5 comments

This may happen if multiples thread read concurrently the ticker value.

馃憤

Looking at the file who handles the critical section, caller does in most cases, invoking update time within critical section. The only case it fails is when reading the time as reported in ticker_read_us (I do not count initialize as that one is run once and at the end is event scheduled).

Protecting the data structure from concurrent updates with a critical section may be a solution.

@c1728p9 @SenRamakri @bulislaw please review

This may happen if multiples thread read concurrently the ticker value.

FWIW, I believe this matches the scenario where I am seeing timer 'tearing'. I have a background thread that is polling an I2C device. and a foreground thread which is calling read_ms on a Timer object. The platform is Nordic RF52832 and the i2c_api platform code for this uses ticker_read_us to check for a timeout on clock-stretching slaves. (Added to address https://github.com/ARMmbed/mbed-os/issues/4826)

Fix for this issue has been provided here: PR https://github.com/ARMmbed/mbed-os/pull/5889.

I've just patched this across to my build and initial impressions are that it has fixed the issue. Thanks!

Closing since all PRs appear to be merged and issue appears to be fixed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ashok-rao picture ashok-rao  路  4Comments

bcostm picture bcostm  路  4Comments

1domen1 picture 1domen1  路  3Comments

toyowata picture toyowata  路  4Comments

drahnr picture drahnr  路  4Comments