forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitaced5a9
committed
Rewrite ConditionVariableBroadcast() to avoid live-lock.
The original implementation of ConditionVariableBroadcast was, per itsself-description, "the dumbest way possible". Thomas Munro found outit was a bit too dumb. An awakened process may immediately re-queueitself, if the specific condition it's waiting for is not yet satisfied.If this happens before ConditionVariableBroadcast is able to see the waitqueue as empty, then ConditionVariableBroadcast will re-awaken the sameprocess, repeating the cycle. Given unlucky timing this back-and-forthcan repeat indefinitely; loops lasting thousands of seconds have beenseen in testing.To fix, add our own process to the end of the wait queue to serve as asentinel, and exit the broadcast loop once our process is not thereanymore. There are various special considerations described in thecomments, the principal disadvantage being that wakers can no longerbe sure whether they awakened a real waiter or just a sentinel. But inpractice nobody pays attention to the result of ConditionVariableSignalor ConditionVariableBroadcast anyway, so that problem seems hypothetical.Back-patch to v10 where condition_variable.c was introduced.Tom Lane and Thomas MunroDiscussion:https://postgr.es/m/CAEepm=0NWKehYw7NDoUSf8juuKOPRnCyY3vuaSvhrEWsOTAa3w@mail.gmail.com1 parent19c47e7 commitaced5a9
1 file changed
+77
-5
lines changedLines changed: 77 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
214 | 214 |
| |
215 | 215 |
| |
216 | 216 |
| |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
217 | 243 |
| |
218 | 244 |
| |
219 |
| - | |
220 |
| - | |
221 |
| - | |
222 |
| - | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
223 | 248 |
| |
224 |
| - | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
225 | 268 |
| |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
226 | 298 |
| |
227 | 299 |
| |
228 | 300 |
|
0 commit comments
Comments
(0)