| 415 | | void run(void) { } |
| | 415 | void run(void) { } |
| | 416 | }; |
| | 417 | |
| | 418 | class NotifyThread : public OpenThreads::Thread { |
| | 419 | public: |
| | 420 | |
| | 421 | NotifyThread(osg::NotifySeverity level, const std::string& message): |
| | 422 | _done(false), |
| | 423 | _level(level), |
| | 424 | _message(message) {} |
| | 425 | |
| | 426 | ~NotifyThread() |
| | 427 | { |
| | 428 | _done = true; |
| | 429 | while(isRunning()) |
| | 430 | { |
| | 431 | OpenThreads::Thread::YieldCurrentThread(); |
| | 432 | } |
| | 433 | } |
| | 434 | |
| | 435 | void run(void) |
| | 436 | { |
| | 437 | std::cout << "Entering thread ..." <<_message<< std::endl; |
| | 438 | |
| | 439 | unsigned int count=0; |
| | 440 | |
| | 441 | while(!_done) |
| | 442 | { |
| | 443 | ++count; |
| | 444 | #if 1 |
| | 445 | osg::notify(_level)<<_message<<this<<"\n"; |
| | 446 | #else |
| | 447 | osg::notify(_level)<<_message<<this<<std::endl; |
| | 448 | #endif |
| | 449 | } |
| | 450 | |
| | 451 | std::cout << "Leaving thread ..." <<_message<< " count="<<count<<std::endl; |
| | 452 | } |
| | 453 | |
| | 454 | bool _done; |
| | 455 | osg::NotifySeverity _level; |
| | 456 | std::string _message; |
| | 457 | |
| | 473 | |
| | 474 | |
| | 475 | std::cout<<"****** Running notify thread test ****** "<<std::endl; |
| | 476 | |
| | 477 | { |
| | 478 | NotifyThread thread1(osg::INFO,"thread one:"); |
| | 479 | NotifyThread thread2(osg::INFO,"thread two:"); |
| | 480 | NotifyThread thread3(osg::INFO,"thread three:"); |
| | 481 | NotifyThread thread4(osg::INFO,"thread four:"); |
| | 482 | thread1.startThread(); |
| | 483 | thread2.startThread(); |
| | 484 | thread3.startThread(); |
| | 485 | thread4.startThread(); |
| | 486 | |
| | 487 | // add a sleep to allow the thread start to fall over it its going to. |
| | 488 | OpenThreads::Thread::microSleep(5000000); |
| | 489 | } |
| | 490 | |
| | 491 | std::cout<<"pass noitfy thread test."<<std::endl<<std::endl; |