Commit d8e4e90
committed
mb2hal: wait for threads to stop before deallocating the memory they're using
This fixes a shutdown-time race condition in mb2hal between the main
thread and the per-link threads.
The main thread connects to all the Modbus interfaces and allocates all
HAL data structures, then starts a worker thread for each modbus link.
The main thread and the worker threads all watch a "time to shutdown"
status variable, which is set by a shutdown signal handler. When the
"time to shutdown" variable gets set, the per-link threads all exit and
the main thread closes down the modbus communications and deallocates
the HAL memory.
But there was no synchronization between the shutdown of the main thread
and the shutdown of the worker threads, so sometimes the worker threads
were still accessing the stuff that the main thread was freeing, leading
to segfaults.
This commit makes the main thread join the worker threads before
deallocating anything.1 parent 9df9b64 commit d8e4e90
1 file changed
Lines changed: 8 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
95 | 94 | | |
96 | 95 | | |
97 | 96 | | |
| |||
105 | 104 | | |
106 | 105 | | |
107 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
108 | 115 | | |
109 | 116 | | |
110 | 117 | | |
| |||
0 commit comments