diff --git a/modules/libcom/src/osi/os/posix/osdThread.c b/modules/libcom/src/osi/os/posix/osdThread.c index da17d9b43a..da0342813e 100644 --- a/modules/libcom/src/osi/os/posix/osdThread.c +++ b/modules/libcom/src/osi/os/posix/osdThread.c @@ -758,6 +758,9 @@ LIBCOM_API void epicsStdCall epicsThreadSetPriority(epicsThreadId pthreadInfo,un assert(epicsThreadOnceCalled); assert(pthreadInfo); if(!pthreadInfo->isEpicsThread) { + /* not allowed to avoid dealing with (potentially) different scheduling + * policies (FIFO vs. RR vs. OTHER vs. ...) + */ fprintf(stderr,"epicsThreadSetPriority called by non epics thread\n"); return; } diff --git a/modules/libcom/test/ringPointerTest.c b/modules/libcom/test/ringPointerTest.c index 45bb1c68f1..987a881fd9 100644 --- a/modules/libcom/test/ringPointerTest.c +++ b/modules/libcom/test/ringPointerTest.c @@ -240,17 +240,32 @@ static void testPair(int locked) epicsRingPointerDelete(ring); } +static +void testInThread(void *raw) +{ + epicsEventId stop = raw; + testPair(0); + testPair(1); + epicsEventMustTrigger(stop); +} + MAIN(ringPointerTest) { - int prio = epicsThreadGetPrioritySelf(); + epicsThreadId tid; + epicsThreadOpts opts = EPICS_THREAD_OPTS_INIT; + epicsEventId stop = epicsEventMustCreate(epicsEventEmpty); testPlan(42); testSingle(); - if (prio) - epicsThreadSetPriority(epicsThreadGetIdSelf(), epicsThreadPriorityScanLow); - testPair(0); - testPair(1); - if (prio) - epicsThreadSetPriority(epicsThreadGetIdSelf(), prio); + /* testPair() needs to run with a priority > 0. + * Start a new thread since main() is a "non-epics" + * thread, for which we can/should not change the priority + */ + opts.joinable = 1; + opts.priority = epicsThreadPriorityScanLow; + tid = epicsThreadCreateOpt("RING", testInThread, stop, &opts); + epicsEventMustWait(stop); + epicsThreadMustJoin(tid); + epicsEventDestroy(stop); return testDone(); }