Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Correct method for thread termination?  (Read 5146 times)

0 Members and 1 Guest are viewing this topic.


  • Newbie
  • *
  • Posts: 40
    • View Profile
Correct method for thread termination?
« on: January 01, 2009, 03:22:03 pm »
Hi all, and happy new year :)

I have a small question regarding threads: I have written a class that inherits from the thread class, let's call it "Mythread". The according thread does nothing but to draw some pixels on the screen all the time (which currently doesn't work, but that's another problem ;) ).

When my main application is about to terminate, this thread should of course also end. My current implementation of this looks (roughly) as follows:
Code: [Select]

void Mythread::Run()
    while ( this->running )
        // call method to draw something

void Mythread::~Mythread()
    this->running = false;

    // call delete for other Mythread-intenal stuff

So my main application does nothing but to call the destructor of the Mythread class when it's about to exit.

I have included some debugging output in the functions shown above, and from what I can see there, this solution seems to work correclty. Anyway, I thought to better ask here if it really is correct or if something is wrong with it.

By the way: While testing this stuff, I made my Linux crash twice. Probably, my mistake was to call Mainwindow.Close() before exiting the thread. So it could have happended that the thread tried to draw to a non-existing window. This, of course, shouldn't lead to a system crash, but there seems to be some bug within the ATI video driver.
The syslog says:
BUG: unable to handle kernel paging request at 0000100000002068
IP: [<ffffffffa022b8d5>] firegl_unlock+0xb5/0x1b0 [fglrx]

I don't know if this could be worked around within the SFML, but as I find this bug rather interesting, I thought I'd post it here ;)