Thread join checks that the thread is started. Test to check the volatile-ness of state member.

master
Denes Matetelki 13 years ago
parent 770f525a8a
commit 6795075697

@ -31,8 +31,9 @@ void Thread::start()
void* Thread::join() const void* Thread::join() const
{ {
TRACE; TRACE;
// if ( !m_isRunning )
// return 0; if ( !m_isRunning )
return 0;
void* retVal; void* retVal;
pthread_join( m_threadHandler, &retVal ); pthread_join( m_threadHandler, &retVal );

@ -68,6 +68,7 @@ private:
{ {
TRACE; TRACE;
// we will got a signal before the sleep finishes
sleep(665); sleep(665);
void* retVal = malloc(sizeof(int)); void* retVal = malloc(sizeof(int));
@ -122,7 +123,7 @@ private:
public: public:
void eetestEmpty( void ) void testEmpty( void )
{ {
TEST_HEADER; TEST_HEADER;
@ -134,16 +135,51 @@ public:
TS_ASSERT_EQUALS ( retVal , (void *)0 ); TS_ASSERT_EQUALS ( retVal , (void *)0 );
} }
// void testJoiningNotStartedThread( void ) void testJoiningNotStartedThread( void )
// { {
// TEST_HEADER; TEST_HEADER;
//
// EmptyThreadClass e; EmptyThreadClass e;
//
// e.stop(); e.stop();
// e.join(); e.join();
// void *retVal = e.join(); void *retVal = e.join();
// TS_ASSERT_EQUALS ( retVal , (void *)0 ); TS_ASSERT_EQUALS ( retVal , (void *)0 );
// } }
private:
class EndlessThread : public Thread
{
private:
void* run( void )
{
TRACE;
/** @note if m_isRunning is not volatile, it can be optimized out
* to a while(1), since body of the loop does not modifies it
*/
while ( m_isRunning )
sleep(1);
return 0;
}
};
public:
void testStatusIsVolatile()
{
TEST_HEADER;
EndlessThread et;
et.start();
sleep(1);
et.stop();
et.join();
}
}; };

Loading…
Cancel
Save