[null,null,["最后更新时间 (UTC):2025-07-30。"],[],[],null,["# Priority inheritance\n\n*Priority inversion* is a situation where a high-priority transaction is\ndelayed by a low-priority task because the low-priority task holds a\nresource needed by the high-priority task. To mitigate priority inversion,\nAndroid supports running threads at different priorities through\nthree different forms of priority inheritance: transaction\npriority inheritance, node priority inheritance, and real-time priority\ninheritance.\n\nThis page explains these different forms of priority inheritance.\n\nTransaction priority inheritance\n--------------------------------\n\nWhen making a synchronous binder call, a high-priority thread can be blocked\nby a low-priority thread until the low-priority thread has sent a reply. For\nexample, a thread with a nice value of -19 can become blocked by a thread with a\ndefault nice value of 0.\n\n*Transaction priority inheritance* fixes this issue because the binder driver\ntemporarily changes the priority of the binder thread handling the transaction\nto match the priority of the caller. When the transaction is done, the binder\ndriver restores the priority of the binder thread to its previous value.\n| **Note:** In an asynchronous transaction, a binder thread doesn't inherit the priority from the caller because an asynchronous transaction doesn't block the caller. While it might be important for the caller to complete the asynchronous transaction as soon as possible, the actual handling of the transaction might not be latency critical, and it would be unnecessary to run the handling thread at a high-priority.\n\nNode priority inheritance\n-------------------------\n\nIn some situations, such as those that require low latency, the\npriority of asynchronous transactions matters.\n\n*Node priority inheritance* lets you configure the minimum priority that all\ntransactions on a node should run at. After node priority inheritance is\nconfigured, all transactions on the node run at this minimum priority.\n| **Note:** If the caller has a higher priority than the node for a synchronous transaction, transactions on the node might run at a higher priority than the node priority inheritance.\n\nThe rules for node priority inheritance are:\n\n- If the transaction is synchronous, the priority becomes\n `max(min_node_priority, caller_priority);`.\n\n- If the transaction is asynchronous, the priority becomes\n `max(default_priority (nice 0), min_node_priority);`.\n\n| **Note:** Real-time priority is always greater than any nice value with a non-real-time priority.\n\n### Configure node priority inheritance\n\nTo configure node priority inheritance, use `BBinder::setMinSchedulerPolicy`.\n\nReal-time priority inheritance\n------------------------------\n\nAndroid uses real-time scheduling policies, such as `SCHED_FIFO`, to cause\nlatency-critical threads to complete their work in time. Additionally, some of\nAndroid's latency-critical work is split over two or more processes.\n\n*Real-time priority inheritance* works identically to nice values, except:\n\n- Real-time priority inheritance is disabled by default.\n- Greater real-time priority values have higher priority than smaller values.\n\n### Enable real-time priority inheritance\n\nReal-time priority inheritance must be enabled for individual nodes\nusing the `BBinder::setInheritRt(true)` call."]]