SFML community forums

Help => System => Topic started by: DingusKhan on March 11, 2015, 11:30:44 pm

Title: Threads
Post by: DingusKhan on March 11, 2015, 11:30:44 pm
Hello.

Today I started looking into using sf::Thread. I've made a class that has an sf::Thread, which is initialized in the constructor. My question is, if the function that runs in that thread has parameters, how would I pass them in?

class ClassWithThread{
public:
    ClassWithThread()
    :mThread(&ClassWithThread::FunctionToUse, this){  //How would I pass the int into that function?

    }

    void FunctionToUse(int x);
private:
    sf::Thread mThread;
};
 

I'm not sure if this is an issue with me not understanding sf::Thread properly, or if it's something I simply can't do.

Thanks in advance for any help.

EDIT: I thought it would be prudent to mention that I'm using SFML 2.1 and Visual Studio Community
Title: Re: Threads
Post by: eXpl0it3r on March 11, 2015, 11:35:02 pm
Either make use of a functor or utilize std::bind.

If you have C++11 compatible compiler (VS 2012/2013), you're better off using std::thread directly.

Also keep in mind that threading is an very advanced topic. If you don't know anything about it, you should get some book on parallel programming and study all the possible issues and solutions.
Title: Re: Threads
Post by: DingusKhan on March 11, 2015, 11:51:18 pm
Thanks! I completely forgot about std::thread, since I started this at my uni where we use VS2010.
Title: Re: Threads
Post by: Lolilolight on March 18, 2015, 03:47:35 pm
There are some books here but I don't know if they are good or not :

Multithread-programming. (http://preshing.com/20120612/an-introduction-to-lock-free-programming/)
Title: Re: Threads
Post by: zsbzsb on March 18, 2015, 04:28:27 pm
There are some books here but I don't know if they are good or not :

Multithread-programming. (http://preshing.com/20120612/an-introduction-to-lock-free-programming/)

Lolilolight, for the last time, stop posting your crap all over the place. The link has absolutely nothing to do with what the OP was asking.