1
System / sf::Thread no apropriate default constructor
« on: December 05, 2010, 02:14:52 am »
Thank you very much!
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
QuoteI built SFML 2.0 [...] using example code found in http://www.sfml-dev.org/tutorials/1.6/system-threads.php
Well, you can't read the 1.6 documentation/tutorials and use 2.0. A lot of things have changed, you should rather refer to the 2.0 documentation:
http://www.sfml-dev.org/documentation/2.0/
Tutorials haven't been updated yet, but the documentation should be enough.
#include <SFML/System.hpp>
#include <iostream>
sf::Mutex GlobalMutex; // This mutex will be used to synchronize our threads
class MyThread : public sf::Thread {
private :
virtual void Run() {
// Lock the mutex, to make sure no thread will interrupt us while we are displaying text
GlobalMutex.Lock();
// Print something...
for (int i = 0; i < 10; ++i)
std::cout << "I'm the thread number 2" << std::endl;
// Unlock the mutex
GlobalMutex.Unlock();
}
};
int main() {
// Create an instance of our custom thread class
MyThread Thread;
// Start it !
Thread.Launch();
// Lock the mutex, to make sure no thread will interrupt us while we are displaying text
GlobalMutex.Lock();
// Print something...
for (int i = 0; i < 10; ++i)
std::cout << "I'm the main thread" << std::endl;
// Unlock the mutex
GlobalMutex.Unlock();
return EXIT_SUCCESS;
}