mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-07-24 15:27:41 +08:00
fix(posix): initialize PX4 before starting the daemon server
The daemon server's client-handler thread spawns module tasks (e.g. dataman). Start px4::init_once()/init() before creating px4_daemon::Server so platform init - uORB, work queues, logging - completes with a happens-before edge to those tasks. Otherwise a module task racing the still-running init reads globals like uORB::Manager's instance pointer or the log message advertisement without synchronization (ThreadSanitizer flags it) - and an atomic would not make it correct, since the publication could simply be skipped.
This commit is contained in:
@@ -368,18 +368,23 @@ int main(int argc, char **argv)
|
||||
register_sig_handler();
|
||||
set_cpu_scaling();
|
||||
|
||||
px4_daemon::Server server(instance);
|
||||
server.start();
|
||||
|
||||
ret = create_dirs();
|
||||
|
||||
if (ret != PX4_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Initialize PX4 (uORB, work queues, logging, ...) before starting the
|
||||
// daemon server. The server's client-handler thread spawns module tasks
|
||||
// (e.g. dataman), so platform init must happen-before that thread is
|
||||
// created. Otherwise those tasks race on globals such as the uORB::Manager
|
||||
// instance pointer and the log message advertisement.
|
||||
px4::init_once();
|
||||
px4::init(argc, argv, "px4");
|
||||
|
||||
px4_daemon::Server server(instance);
|
||||
server.start();
|
||||
|
||||
// Don't set this up until PX4 is up and running
|
||||
ret = set_server_running(instance);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user