int main() { static const int NUM_THREADS = 64; typedef boost::array<boost::thread, NUM_THREADS> Threads; std::cout<<"hardware concurrency "<<boost::thread::hardware_concurrency()<<std::endl; std::cout<<"threads "<<NUM_THREADS<<std::endl; std::cout<<"iterations per threads "<<NUM_IT<<std::endl; volatile int i = 0; boost::barrier barrier(NUM_THREADS); Threads threads; for(Threads::iterator it = threads.begin(); it != threads.end(); ++it) { *it = boost::thread(boost::bind(&IncThreadFunc, &barrier, &i)); } for(Threads::iterator it = threads.begin(); it != threads.end(); ++it) { (*it).join(); } std::cout<<"result "<<i<<" expected "<<(NUM_THREADS*NUM_IT)<<" ("<<(NUM_THREADS*NUM_IT-i)<<")"<<std::endl; return 0; }
Viewer::~Viewer() { //OSG_NOTICE<<"Viewer::~Viewer()"<<std::endl; Threads threads; getAllThreads(threads); OSG_INFO<<"Viewer::~Viewer():: start destructor getThreads = "<<threads.size()<<std::endl; stopThreading(); if (_scene.valid() && _scene->getDatabasePager()) { _scene->getDatabasePager()->cancel(); _scene->setDatabasePager(0); } Contexts contexts; getContexts(contexts); // clear out all the previously assigned operations for(Contexts::iterator citr = contexts.begin(); citr != contexts.end(); ++citr) { (*citr)->close(); } //OSG_NOTICE<<"finish Viewer::~Viewer()"<<std::endl; getAllThreads(threads); OSG_INFO<<"Viewer::~Viewer() end destructor getThreads = "<<threads.size()<<std::endl; }
void CompositeViewer::getAllThreads(Threads& threads, bool onlyActive) { OperationThreads operationThreads; getOperationThreads(operationThreads); for(OperationThreads::iterator itr = operationThreads.begin(); itr != operationThreads.end(); ++itr) { threads.push_back(*itr); } Scenes scenes; getScenes(scenes); for(Scenes::iterator sitr = scenes.begin(); sitr != scenes.end(); ++sitr) { Scene* scene = *sitr; osgDB::DatabasePager* dp = scene->getDatabasePager(); if (dp) { for(unsigned int i=0; i<dp->getNumDatabaseThreads(); ++i) { osgDB::DatabasePager::DatabaseThread* dt = dp->getDatabaseThread(i); if (!onlyActive || dt->isRunning()) { threads.push_back(dt); } } } } }
Threads ThreadsHandler::parseGdbmiThreads(const GdbMi &data, int *currentThread) { // ^done,threads=[{id="1",target-id="Thread 0xb7fdc710 (LWP 4264)", // frame={level="0",addr="0x080530bf",func="testQString",args=[], // file="/.../app.cpp",fullname="/../app.cpp",line="1175"}, // state="stopped",core="0"}],current-thread-id="1" const QList<GdbMi> items = data.findChild("threads").children(); const int n = items.size(); Threads threads; threads.reserve(n); for (int index = 0; index != n; ++index) { bool ok = false; const GdbMi item = items.at(index); const GdbMi frame = item.findChild("frame"); ThreadData thread; thread.id = item.findChild("id").data().toInt(); thread.targetId = QString::fromLatin1(item.findChild("target-id").data()); thread.core = QString::fromLatin1(item.findChild("core").data()); thread.state = QString::fromLatin1(item.findChild("state").data()); thread.address = frame.findChild("addr").data().toULongLong(&ok, 0); thread.function = QString::fromLatin1(frame.findChild("func").data()); thread.fileName = QString::fromLatin1(frame.findChild("fullname").data()); thread.lineNumber = frame.findChild("line").data().toInt(); thread.module = QString::fromLocal8Bit(frame.findChild("from").data()); // Non-GDB (Cdb2) output name here. thread.name = QString::fromLatin1(frame.findChild("name").data()); threads.append(thread); } if (currentThread) *currentThread = data.findChild("current-thread-id").data().toInt(); return threads; }
void IPCEngineHost::selectThread(int index) { resetLocation(); Threads threads = threadsHandler()->threads(); QTC_ASSERT(index < threads.size(), return); QByteArray p; { QDataStream s(&p, QIODevice::WriteOnly); SET_NATIVE_BYTE_ORDER(s); s << quint64(threads.at(index).id); } rpcCall(SelectThread, p); }
void threadFinishedSlot() { auto const thread = qobject_cast<QThread*>(QObject::sender()); QMutexLocker lock(&m_mutex); auto it = m_threads.find(thread); if (it == m_threads.end()) return; auto const histogram(it->histogram); bool stuck = it->stuck; m_threads.erase(it); lock.unlock(); emit newHistogram(thread, histogram); if (stuck) emit loopStateChanged(thread, 0); emit threadFinished(thread); }
Viewer::~Viewer() { //OSG_NOTICE<<"Viewer::~Viewer()"<<std::endl; Threads threads; getAllThreads(threads); OSG_INFO<<"Viewer::~Viewer():: start destructor getThreads = "<<threads.size()<<std::endl; stopThreading(); if (_scene.valid() && _scene->getDatabasePager()) { _scene->getDatabasePager()->cancel(); _scene->setDatabasePager(0); } Contexts contexts; getContexts(contexts); // clear out all the previously assigned operations for(Contexts::iterator citr = contexts.begin(); citr != contexts.end(); ++citr) { osg::GraphicsContext* gc = *citr; // Run destroy operation on each context before closing it if (_cleanUpOperation.valid() && gc->valid()) { gc->makeCurrent(); (*_cleanUpOperation)(gc); gc->releaseContext(); } gc->close(); } //OSG_NOTICE<<"finish Viewer::~Viewer()"<<std::endl; getAllThreads(threads); OSG_INFO<<"Viewer::~Viewer() end destructor getThreads = "<<threads.size()<<std::endl; }
std::string gdbmiThreadList(CIDebugSystemObjects *debugSystemObjects, CIDebugSymbols *debugSymbols, CIDebugControl *debugControl, CIDebugAdvanced *debugAdvanced, std::string *errorMessage) { Threads threads; ULONG currentThreadId; if (!threadList(debugSystemObjects, debugSymbols, debugControl, debugAdvanced, &threads, ¤tThreadId, errorMessage)) return std::string(); std::ostringstream str; str << "{threads=["; const Threads::const_iterator cend = threads.end(); for (Threads::const_iterator it = threads.begin(); it != cend; ++it) it->formatGDBMI(str); str << "],current-thread-id=\"" << currentThreadId << "\"}"; return str.str(); }
void GlutViewer::Start(int argc, char** argv, int w, int h, float r) { a_argc = argc; a_argv = argv; width = w; height = h; rad = r; threads.create(glut_thread, 0); }
int main() { static const int NUM_THREADS = 64; typedef boost::array<boost::thread, NUM_THREADS> Threads; std::cout<<"hardware concurrency "<<boost::thread::hardware_concurrency()<<std::endl; std::cout<<"threads "<<NUM_THREADS<<std::endl; std::cout<<"iterations per threads "<<NUM_IT<<std::endl; volatile int i = 0; boost::condition_variable cond; boost::mutex mut; volatile int started = 0; Threads threads; for(Threads::iterator it = threads.begin(); it != threads.end(); ++it) { *it = boost::thread(boost::bind(&IncThreadFunc, &started, &i, &cond, &mut)); } while(started < NUM_THREADS) { boost::this_thread::sleep(boost::posix_time::milliseconds(10)); } cond.notify_all(); for(Threads::iterator it = threads.begin(); it != threads.end(); ++it) { (*it).join(); } std::cout<<"result "<<i<<" expected "<<(NUM_THREADS*NUM_IT)<<" ("<<(NUM_THREADS*NUM_IT-i)<<")"<<std::endl; return 0; }
void ThreadsHandler::setThreads(const Threads &threads) { beginResetModel(); m_threads = threads; bool found = false; for (int i = 0, n = m_threads.size(); i < n; ++i) if (threads.at(i).id == m_currentId) { found = true; break; } if (!found) m_currentId = ThreadId(); m_resetLocationScheduled = false; endResetModel(); updateThreadBox(); }
int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc, argv); // construct the viewer. osgViewer::Viewer viewer(arguments); typedef std::list< osg::ref_ptr<osg::OperationThread> > Threads; Threads operationThreads; osg::ref_ptr<UpdateTextOperation> updateOperation; unsigned int numThreads = 0; if (arguments.read("--mt", numThreads) || arguments.read("--mt")) { // construct a multi-threaded text updating test. if (numThreads==0) numThreads = 1; // create a group to add everything into. osg::Group* mainGroup = new osg::Group; osg::Vec3 center(0.5f,0.5f,0.5f); float diameter = 1.0f; osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments); if (loadedModel.valid()) { mainGroup->addChild(loadedModel.get()); center = loadedModel->getBound().center(); diameter = loadedModel->getBound().radius() * 2.0f; } for(unsigned int i=0; i<numThreads; ++i) { osg::Group* textGroup = new osg::Group; mainGroup->addChild(textGroup); // create the background thread osg::OperationThread* operationThread = new osg::OperationThread; operationThreads.push_back(operationThread); // create the operation that will run in the background and // sync once per frame with the main viewer loop. updateOperation = new UpdateTextOperation(center, diameter, textGroup); // add the operation to the operation thread and start it. operationThread->add(updateOperation.get()); operationThread->startThread(); // add the operation to the viewer to sync once per frame. viewer.addUpdateOperation(updateOperation.get()); // add a unit cube for the text to appear within. osg::Geode* geode = new osg::Geode; geode->getOrCreateStateSet()->setAttribute(new osg::PolygonMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE)); geode->addDrawable(new osg::ShapeDrawable(new osg::Box(center,diameter))); mainGroup->addChild(geode); } viewer.setSceneData(mainGroup); } else { // prepare scene. osg::Vec3 center(0.0f,0.0f,0.0f); float radius = 1.0f; // make sure the root node is group so we can add extra nodes to it. osg::Group* group = new osg::Group; if (true) { // create the hud. osg::Camera* camera = new osg::Camera; camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); camera->setProjectionMatrixAsOrtho2D(0,1280,0,1024); camera->setViewMatrix(osg::Matrix::identity()); camera->setClearMask(GL_DEPTH_BUFFER_BIT); camera->addChild(createHUDText()); camera->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF); group->addChild(camera); } if (true) { group->addChild(create3DText(center,radius)); } // set the scene to render viewer.setSceneData(group); } std::string filename; if (arguments.read("-o",filename)) { osgDB::writeNodeFile(*viewer.getSceneData(),filename); return 0; } viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); viewer.addEventHandler(new osgViewer::StatsHandler()); viewer.run(); if (!operationThreads.empty()) { for(Threads::iterator itr = operationThreads.begin(); itr != operationThreads.end(); ++itr) { (*itr)->cancel(); } } return 0; }