Hi Robert, Curtis implemented the same code with pthreads (attached) which seam to work, so it is definitely a bug in OpenThreads (for linux only, Windows implementation seam to be working). Just FYI
Nick On Mon, May 5, 2014 at 3:23 PM, Curtis Rubel <cru...@compro.net> wrote: > Hi, > > Checked out the latest trunk version myself and I am still having the same > issues here with the OpenThread calls and the example code I sent to Nick. > We are running OpenSuse 12.3 64-bit here. > > The calls all return good status. In fact the getSchedulePolicy and the > getSchedulePriority return the same level that was set, but the linux > system calls do not show any change in the threads priority, scheduling > policy or affinity. > > Tried running the example as normal user and the root user and get the > same exact results so does not seem to be any sort of issue with > priviledges at this point either. > > > Thank you! > > Cheers, > Curtis > > ------------------ > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=59262#59262 > > > > > > _______________________________________________ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > -- trajce nikolov nick
/* -*-c++-*- Copyright (C) 2010 Wang Rui <wangray84 at gmail dot com> * OpenSceneGraph Beginners Guide * Using a separate thread for supplying data to a node in the main process */ #include <osg/Geode> #include <osgDB/ReadFile> #include <osgText/Text> #include <osgViewer/Viewer> #include <iostream> //#define OPENTHREADS_ENABLED #ifdef OPENTHREADS_ENABLED class DataReceiverThread : public OpenThreads::Thread { public: virtual int cancel() { _done = true; while( isRunning() ) YieldCurrentThread(); return 0; } virtual void run() { _done = false; _dirty = true; do { YieldCurrentThread(); char ch; std::cin.get(ch); printf("[%c][%d] ", ch, ch); switch (ch) { case 0: break; // We don¡¯t want ¡®\0¡¯ to be added case 9: _done = true; break; // Tab = 9 default: addToContent(ch); break; } } while( !_done ); } void addToContent( int ch ) { OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex); _content += ch; _dirty = true; } bool getContent( std::string& str ) { OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex); if ( _dirty ) { str += _content; _dirty = false; return true; } return false; } protected: OpenThreads::Mutex _mutex; std::string _content; bool _done; bool _dirty; }; #else #include <pthread.h> class DataReceiverThread { public: DataReceiverThread() { _mutex = PTHREAD_MUTEX_INITIALIZER; pthread_attr_init(&custom_sched_attr); CPU_ZERO(&cpuset); CPU_SET(7,&cpuset); pthread_attr_setscope(&custom_sched_attr, PTHREAD_SCOPE_SYSTEM); pthread_attr_setinheritsched(&custom_sched_attr, PTHREAD_EXPLICIT_SCHED); pthread_attr_setschedpolicy(&custom_sched_attr, SCHED_FIFO); fifo_max_prio = sched_get_priority_max(SCHED_FIFO); fifo_min_prio = sched_get_priority_min(SCHED_FIFO); fifo_mid_prio = (fifo_min_prio + fifo_max_prio)/2; fifo_param.sched_priority = fifo_mid_prio; pthread_attr_setschedparam(&custom_sched_attr, &fifo_param); } ~DataReceiverThread(); virtual int cancel() { _done = true; sched_yield(); return 0; } virtual void run() { _done = false; _dirty = true; do { sched_yield(); char ch; std::cin.get(ch); printf("[%c][%d] ", ch, ch); switch (ch) { case 0: break; // We don¡¯t want ¡®\0¡¯ to be added case 9: _done = true; break; // Tab = 9 default: addToContent(ch); break; } } while( !_done ); } bool StartInternalThread() { bool status; if(pthread_create(&_thread, &custom_sched_attr, DataRcvrThreadFunc, this) == 0) status = true; else status = false; if(status) status = pthread_setaffinity_np(_thread, sizeof(cpu_set_t), &cpuset); return status; } void addToContent( int ch ) { pthread_mutex_lock(&_mutex); _content += ch; _dirty = true; pthread_mutex_unlock(&_mutex); } bool getContent( std::string& str ) { if ( _dirty ) { pthread_mutex_lock(&_mutex); str += _content; _dirty = false; pthread_mutex_unlock(&_mutex); return true; } return false; } protected: pthread_t _thread; pthread_mutex_t _mutex; pthread_attr_t custom_sched_attr; struct sched_param fifo_param; int fifo_max_prio; int fifo_mid_prio; int fifo_min_prio; cpu_set_t cpuset; std::string _content; bool _done; bool _dirty; private: static void * DataRcvrThreadFunc(void * This) {((DataReceiverThread *)This)->run(); return NULL;} }; #endif class UpdateTextCallback : public osg::Drawable::UpdateCallback { public: UpdateTextCallback(DataReceiverThread* rcvrthrd) : rcvrthread(rcvrthrd) {} virtual void update( osg::NodeVisitor* nv, osg::Drawable* drawable ) { osgText::Text* text = static_cast<osgText::Text*>( drawable ); if ( text ) { std::string str("# "); // if ( DataReceiverThread::instance()->getContent(str) ) if ( rcvrthread->getContent(str) ) text->setText( str ); } } DataReceiverThread* rcvrthread; }; int main( int argc, char** argv ) { int status; osg::ref_ptr<osgText::Text> text = new osgText::Text; text->setFont( "fonts/arial.ttf" ); text->setAxisAlignment( osgText::TextBase::SCREEN ); text->setDataVariance( osg::Object::DYNAMIC ); text->setInitialBound( osg::BoundingBox(osg::Vec3(), osg::Vec3(400.0f, 20.0f, 20.0f)) ); DataReceiverThread* rcvrthread = new DataReceiverThread; text->setUpdateCallback( new UpdateTextCallback(rcvrthread)); osg::ref_ptr<osg::Geode> geode = new osg::Geode; geode->addDrawable( text.get() ); geode->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF ); osgViewer::Viewer viewer; viewer.setSceneData( geode.get() ); viewer.setUpViewInWindow( 50, 50, 640, 480 ); #ifdef OPENTHREADS_ENABLED status = rcvrthread->setProcessorAffinity(2); printf("setProcessorAffinity status: %d\n", status); status = rcvrthread->setSchedulePolicy(OpenThreads::Thread::THREAD_SCHEDULE_ROUND_ROBIN); printf("setSchedulePolicy status: %d\n", status); if(!status) printf("getSchedulePolicy: %d\n",rcvrthread->getSchedulePolicy()); status = rcvrthread->setSchedulePriority(OpenThreads::Thread::THREAD_PRIORITY_HIGH); printf("setSchedulePriority status: %d\n", status); if(!status) printf("getSchedulePriority: %d\n",rcvrthread->getSchedulePriority()); rcvrthread->Init(); rcvrthread->startThread(); #else status = rcvrthread->StartInternalThread(); #endif viewer.run(); rcvrthread->cancel(); return 0; }
_______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org