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

Author Topic: [SFML 2.0 RC] - Threads  (Read 16616 times)

0 Members and 1 Guest are viewing this topic.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: [SFML 2.0 RC] - Threads
« Reply #15 on: June 09, 2012, 09:51:02 am »
Quote
warning C4355: 'this' : used in base member initializer list
Using 'this' in the initializer list triggers a warning on VC++, yes. The only way to get rid of it is to disable it. Or to allocate your sf::Thread instance dynamically so that it can be constructed outside the initializer list.

Quote
I am sad it still can't run on FreeBSD.
If you have something relevant to say related to this thread, please say it clearly.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: [SFML 2.0 RC] - Threads
« Reply #16 on: June 09, 2012, 03:37:17 pm »
Is there a good way to avoid that, or should I just not mind? Simply suppressing the warning is not a good solution in my opinion.
You can disable it locally with
#pragma warning(push)
#pragma warning(disable: 4355)

// code

#pragma warning(pop)

I wouldn't use dynamic allocations just to avoid the warning.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Celtic Minstrel

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: [SFML 2.0 RC] - Threads
« Reply #17 on: June 26, 2012, 02:11:04 am »
It's generally not a good idea to pass this in the initializer list because at that point it's not finished being constructed. However, in this case you know that Thread isn't going to access it until you later call .launch(), so it's safe to ignore the warning.

I don't think there's a way to avoid the warning given the current API.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: [SFML 2.0 RC] - Threads
« Reply #18 on: June 26, 2012, 08:13:48 am »
Quote
I don't think there's a way to avoid the warning given the current API.
There will be one when C++11 features are added: the move assignment operator.
Laurent Gomila - SFML developer

Celtic Minstrel

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: [SFML 2.0 RC] - Threads
« Reply #19 on: June 26, 2012, 03:49:13 pm »
Would that really be able to avoid the warning? I thought Thread didn't have a default constructor.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: [SFML 2.0 RC] - Threads
« Reply #20 on: June 26, 2012, 03:54:38 pm »
I think it would have one in this case.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: [SFML 2.0 RC] - Threads
« Reply #21 on: June 26, 2012, 10:15:04 pm »
I think it would have one in this case.
In case you mean "default constructor" with "one": Do you really want to allow invalid (default-constructed) threads to avoid this warning?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: [SFML 2.0 RC] - Threads
« Reply #22 on: June 26, 2012, 10:25:34 pm »
Quote
In case you mean "default constructor" with "one": Do you really want to allow invalid (default-constructed) threads to avoid this warning?
Not just to avoid this warning, but to allow defining a thread after its construction, without forcing dynamic allocation.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: [SFML 2.0 RC] - Threads
« Reply #23 on: June 26, 2012, 10:29:57 pm »
And what happens when launch(), wait() or terminate() is called on an invalid thread? I don't know if just doing nothing is a good idea...
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

MorleyDev

  • Full Member
  • ***
  • Posts: 219
  • "It is not enough for code to work."
    • View Profile
    • http://www.morleydev.co.uk/
Re: [SFML 2.0 RC] - Threads
« Reply #24 on: June 26, 2012, 11:09:56 pm »
Launch: This is the one stickler. The stl gets around this because threads to launch as soon as constructed, instead of a manual launch function. I guess you could just make launch() throw or return some kind of error?

Wait: Would wait not just do nothing? It's a join command, a finished thread just keeps going here (well, with std at least throwing on any exceptions in the process), so I'd assume an invalid thread does nothing too...

Terminate: Is there a context in which SFML will be used where any way of forcibly terminating a thread is the best option? That aside, again how is are invalid thread and a finished thread different to an outside observer? Terminating a finished thread, presumably does nothing.

In the interests of honest, I've never used SFML's threading library. Always favoured boost threads, or C++11 threads when available (To simplify this I actually wrote a bit of code to drag in and turn a boost thread into the appropriate std:: versions with correct functions and parameters).
« Last Edit: June 26, 2012, 11:14:40 pm by MorleyDev »
UnitTest11 - A unit testing library in C++ written to take advantage of C++11.

All code is guilty until proven innocent, unworthy until tested, and pointless without singular and well-defined purpose.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: [SFML 2.0 RC] - Threads
« Reply #25 on: June 27, 2012, 08:03:54 am »
If a default-constructed thread is considered "empty" (no function), it makes sense to do nothing in these functions.

Anyway, the problem is still: how to allow changing the definition of a thread after its construction, without dynamic allocation. It's not about allowing or not a default constructor ;)
Laurent Gomila - SFML developer

MorleyDev

  • Full Member
  • ***
  • Posts: 219
  • "It is not enough for code to work."
    • View Profile
    • http://www.morleydev.co.uk/
Re: [SFML 2.0 RC] - Threads
« Reply #26 on: June 27, 2012, 01:38:38 pm »
Well without move constructors or similar (how boost fakes it), the only solution I can think of (and I'm sure you have already considered) is a "construct" or "setFunction" function or something? Which isn't the prettiest solution...

Then again, functionally I guess that isn't much different from a move constructor.
UnitTest11 - A unit testing library in C++ written to take advantage of C++11.

All code is guilty until proven innocent, unworthy until tested, and pointless without singular and well-defined purpose.

Silvah

  • Guest
Re: [SFML 2.0 RC] - Threads
« Reply #27 on: June 27, 2012, 04:34:21 pm »
Quote
In case you mean "default constructor" with "one": Do you really want to allow invalid (default-constructed) threads to avoid this warning?
Not just to avoid this warning, but to allow defining a thread after its construction, without forcing dynamic allocation.
With enough Boost, this is already kind of possible.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: [SFML 2.0 RC] - Threads
« Reply #28 on: June 27, 2012, 04:40:44 pm »
Quote
With enough Boost, this is already kind of possible.
That works for people who use boost, but it would be cool to have a solution that works for others too, something built in SFML.
Laurent Gomila - SFML developer

Silvah

  • Guest
Re: [SFML 2.0 RC] - Threads
« Reply #29 on: June 27, 2012, 08:12:21 pm »
That works for people who use boost, but it would be cool to have a solution that works for others too, something built in SFML.
Sure, I'm just saying that if someone badly needs that right now, it's possible.