简体   繁体   中英

How to fix processor affinity for Qt 5.9 Thread on Windows with Ryzen 7

I have been developing a program for my Master's Thesis with OpenSceneGraph-3.4.0 and GUI from Qt 5.9 (otherwise in Visual Studio 2015 and 2017). At work everything works fine, but now that I have a new Computer at home I tried to get it running.

However, when I call the frame() method for the viewer, I get a Read Access Violation in QtThread.cpp at the setProcessorAffinity(unsigned int cpunum) , specifically in the following line:

QtThreadPrivateData* pd = static_cast<QtThreadPrivateData*>(_prvData);

Here is the complete function (QtThread.cpp is part of OpenThreads of OSG):

// Description:  set processor affinity for the thread
//
// Use: public
//
int Thread::setProcessorAffinity(unsigned int cpunum)
{
    QtThreadPrivateData* pd = static_cast<QtThreadPrivateData*>(_prvData);
    pd->cpunum = cpunum;
    if (!pd->isRunning) return 0;

    // FIXME:
    // Qt doesn't have a platform-independent thread affinity method at present.
    // Does it automatically configure threads on different processors, or we have to do it ourselves?
    return -1;
}

The viewer in OSG is set to osgViewer::Viewer::SingleThreaded , but if I remove that line I get an error "Cannot make QOpenGLContext current in a different thread" in GraphicsWindowQt.cpp (which is part of OsgQt), so that's probably a dead end.


Edit for clarification

I call frame() on the osgViewer::Viewer object. In this function, the viewer calls realize() (which is a function of the Viewer class). In there setUpThreading() is called (which is a function of the Viewer Base class). This in turn calls OpenThreads::SetProcessorAffinityOfCurrentThread(0) In there, the following code is executed:

Thread* thread = Thread::CurrentThread();
if (thread)
    return thread->setProcessorAffinity(cpunum);

thread (after the first line) has a value 0x00000000fdfdfdfd which looks like an error to me. In any case, the last call is the one I posted in my original question.


I don't even have an idea of where to start fixing this. I assume, it's some processor related problem. My processor is a Ryzen 7 1700 (at work it's an Intel i7 3770k), so maybe that helps. Otherwise, at home I'm using Windows 10, wheras at work it's Windows 7.

I'd be thankful for any help at all.

So in the end, it seems to be a problem with OpenThreads (and thus the OpenSceneGraph part, which I can do nothing about). When using cmake for the OpenSceneGraph source, there is an option "BUILD_OPENTHREADS_WITH_QT" that needs to be disabled .

I found the solution in this thread in the OSG forum , so thanks to this guy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM