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

Author Topic: Threads  (Read 4341 times)

0 Members and 1 Guest are viewing this topic.

DingusKhan

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Threads
« 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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Threads
« Reply #1 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.
« Last Edit: March 11, 2015, 11:36:51 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

DingusKhan

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: Threads
« Reply #2 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.

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: Threads
« Reply #3 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.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Threads
« Reply #4 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.

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.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor