Changeset 99704 in vbox
- Timestamp:
- May 9, 2023 5:01:36 PM (19 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/tstRTSemEvent.cpp
r98103 r99704 166 166 static void test1(void) 167 167 { 168 RTTestISub("T hreethreads");168 RTTestISub("Two threads"); 169 169 170 170 /* … … 185 185 RTThreadSleep(256); 186 186 187 #if defined(RT_OS_SOLARIS) 188 /* 189 * The Single UNIX Specification v2 states: "If more than one thread is blocked on a 190 * condition variable, the scheduling policy determines the order in which threads 191 * are unblocked." On Solaris, the default scheduling policy, SCHED_OTHER, does not 192 * specify the order in which multiple threads blocked on a condition variable are 193 * awakened. Thus we can't guarantee which thread will wake up when the condition 194 * variable is signalled so instead of verifying the order of thread wakeup we 195 * simply verify that two signals wake both threads. 196 */ 197 /* Signal twice to wake up both threads */ 198 RTTESTI_CHECK_RC(RTSemEventSignal(hSem), VINF_SUCCESS); 199 RTThreadSleep(256); 200 RTTESTI_CHECK_RC(RTSemEventSignal(hSem), VINF_SUCCESS); 201 202 RTTESTI_CHECK_RC(RTThreadWait(hThread1, 5000, NULL), VINF_SUCCESS); 203 RTTESTI_CHECK_RC(RTThreadWait(hThread2, 5000, NULL), VINF_SUCCESS); 204 #else 205 /* 206 * The Linux sched(7) man page states: "SCHED_OTHER is the standard Linux 207 * time-sharing scheduler ... the thread chosen to run is based on a dynamic 208 * priority that ... is based on the nice value and is increased for each time 209 * quantum the thread is ready to run, but denied to run by the scheduler." This 210 * means that in practice the thread blocked longest on the condition variable will 211 * be awakened first and thus we can verify the ordering below. FreeBSD and macOS 212 * don't seem to document their implementations for this scenario but empirically 213 * they behave similar to Linux. 214 */ 187 215 /* Signal once, hopefully waking up thread1: */ 188 216 RTTESTI_CHECK_RC(RTSemEventSignal(hSem), VINF_SUCCESS); … … 192 220 RTTESTI_CHECK_RC(RTSemEventSignal(hSem), VINF_SUCCESS); 193 221 RTTESTI_CHECK_RC(RTThreadWait(hThread2, 5000, NULL), VINF_SUCCESS); 222 #endif 194 223 195 224 RTTESTI_CHECK_RC(RTSemEventDestroy(hSem), VINF_SUCCESS);
Note:
See TracChangeset
for help on using the changeset viewer.