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

Author Topic: Question about destructors of some classes.  (Read 1786 times)

0 Members and 1 Guest are viewing this topic.

vechestva

  • Newbie
  • *
  • Posts: 25
    • View Profile
Question about destructors of some classes.
« on: May 18, 2013, 01:23:03 pm »
Good day.
I have a question.
Why destructors some classes:
sf::~TcpSocket, sf::~Thread
do not call methods:
sf::TcpSocke::disconnect(),  sf::Thread::terminate()
?
When using them appear some discomfort, for example:
sf::Thread* thread= new sf::Thread(&fooo);
thread.launch();
...
delete thread;
The thread is still active, you have to manually call thread->terminate().

ps: And yet, it would be nice to add the processing status for threads. (sf::Thread::Status)
I do not know much English.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Question about destructors of some classes.
« Reply #1 on: May 18, 2013, 01:30:38 pm »
The thread is still active, you have to manually call thread->terminate().
No, you should not call terminate() in normal situations. sf::Thread::~Thread() invokes wait(), therefore it waits until the thread is finished. Just let your thread end regularly.

Concerning sf::TcpSocket, the base class destructor ~Socket() invokes close().


When using them appear some discomfort, for example:
sf::Thread* thread= new sf::Thread(&fooo);
thread.launch();
...
delete thread;
The discomfort here is to have new and delete, instead of adhering to RAII and using automatic variables:
sf::Thread thread(&foo);
thread.launch();


ps: And yet, it would be nice to add the processing status for threads. (sf::Thread::Status)
What is the "processing status"?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

vechestva

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Question about destructors of some classes.
« Reply #2 on: May 18, 2013, 01:46:25 pm »
The thread is still active, you have to manually call thread->terminate().
No, you should not call terminate() in normal situations. sf::Thread::~Thread() invokes wait(), therefore it waits until the thread is finished. Just let your thread end regularly.

Concerning sf::TcpSocket, the base class destructor ~Socket() invokes close().
Thanks, now I understand.

What is the "processing status"?
Whether running launch()?
I would like to use a list of pointers to thread (std::list<sf::Thread*>), but i have to use a pair. (std::list <std::pair<sf::Thread*, bool /*isLaunched*/>>) or a map.
« Last Edit: May 18, 2013, 01:50:53 pm by vechestva »
I do not know much English.

 

anything