Make properties fully thread-safe

From FlightGear wiki
Jump to navigation Jump to search


Title: Make properties fully thread-safe

[[File: |thumbnail|]]

Potential mentors: Julian Smith
Intro: (short intro)
Interested Parties: (feel free to add yourself)
Status:

Post-hackathon write-up (2021-11-7)

Summary:

  • Changed properties API to make getStringValue() return a std::string by value.
  • Modified code in flightgear and simgear to use new API.
  • 3,000 line diff.
  • Appears to run fine except for two issues:
    • Approx 10% slow-down (found using the new Performance testing by replaying recordings system developed in the same Hackathon).
    • The Aircraft menu is corrupted - all items are displayed with the same text "Translations/defualt/menu.xml".

Next steps:

  • Fix the cause of the menu bug.
  • Write a stress test - lots of threads all reading/writing properties, adding/removing listeners etc.
  • Investigate the slow-down:
    • Hopefully we will be able to change calling code to avoid the overhead.
    • The point was made in the final Hackathon meeting that a 10% slowdown might not matter too much if thread-safe properties allowed us to make better use of threads throughout Flightgear.
Summary: Change property system to return std::string by value instead of char*.
Background: The properties system was made mostly thread-safe in early 2021 using read/write locks (see SimGear commit f1dd7901cbb9ed5fb342ae1ec2ac982b915fb9f0). However some methods such as SGPropertyNode::getStringValue() still return a char* pointer into the property's internal data, which is not thread-safe.
Details: Returning std::string by value might affect performance, so we'll need to profile before/after. It's likely that we can fix performance problems by modifying calling code, e.g. caching string values outside loops etc.
Ideas:
Required skills: C++
Learning Opportunities:
Notes:
References