VirtualBox

Changeset 99704 in vbox


Ignore:
Timestamp:
May 9, 2023 5:01:36 PM (19 months ago)
Author:
vboxsync
Message:

Runtime/testcase/tstRTSemEvent: test1() queues up two threads behind a
condition variable and then sends a signal to the condition variable and
verifies that the first thread queued was awakened. This fails on
Solaris since the order in which multiple threads blocked on a condition
variable are awakened is unspecified in the default scheduling class
(SCHED_OTHER). Fixed by simplifying the test for Solaris systems to
simply send two signals and then check that both of the waiting threads
have been awakened.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/testcase/tstRTSemEvent.cpp

    r98103 r99704  
    166166static void test1(void)
    167167{
    168     RTTestISub("Three threads");
     168    RTTestISub("Two threads");
    169169
    170170    /*
     
    185185    RTThreadSleep(256);
    186186
     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     */
    187215    /* Signal once, hopefully waking up thread1: */
    188216    RTTESTI_CHECK_RC(RTSemEventSignal(hSem), VINF_SUCCESS);
     
    192220    RTTESTI_CHECK_RC(RTSemEventSignal(hSem), VINF_SUCCESS);
    193221    RTTESTI_CHECK_RC(RTThreadWait(hThread2, 5000, NULL), VINF_SUCCESS);
     222#endif
    194223
    195224    RTTESTI_CHECK_RC(RTSemEventDestroy(hSem), VINF_SUCCESS);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette