Conversation started Dec 17, 2012 at 15:28.
Dec 17, 2012 15:28
Why don't you just use async?
user142019
I am joining it.
user142019
What happens if you join a thread and it has already ended?
Nothing.
When you say the dtor throws, do you mean std::terminate?
user142019
Uh yes. :P
That happens when the thread is destroyed in a joinable state.
user142019
Dec 17, 2012 15:31
Hmm.
user142019
Ohh wait I think I know what's happening. Something throws an exception before I join the thread.
3 mins ago, by R. Martinho Fernandes
Why don't you just use async?
In case you haven't noticed yet, std::thread is very finicky to get right.
user142019
I have noticed. :P
In case you haven't noticed, he noiticed.
meta noticed
user142019
Dec 17, 2012 15:33
Ah promise::set_value throws.
user142019
Let's see.
Why don't you just use packaged_task?
@R.MartinhoFernandes packaged_task... I really need to put that book on the list for christmas break
Scroll up for example.
All that said, std::async can be a bit tricky as well.
@R.MartinhoFernandes std::thread(std::move(task)).detach(); would that have merit?
Dec 17, 2012 15:38
Hmm, yeah, I forgot to move. Detaching avoids the need to join. It is quite a mouthful though; std::async is better :P
Or not. This is all very messy.
@R.MartinhoFernandes Also, async has a more flexible specification.
there's some work-stealing ... something which it can do, but std::thread can't
But async suxors because you need to grab the future yourself.
std::async(std::launch::async, fun);
do_stuff();
// runs sequentially, using two threads :(
user142019
Screw this. I'll use Erlang. :^)
auto dummy = std::async(std::launch::async, fun);
do_stuff();
// fixed
user142019
Dec 17, 2012 15:44
if (::fork() == 0) ::execlp("erl", nullptr);
std::exit(0);
// fixed
it's cold
user142019
it's hot
So, yeah, both async and thread have broken interfaces :(
it's mild
user142019
it's humid
Dec 17, 2012 15:46
it's suckage
user142019
it's the vacuum cleaner!
it's an industrial-grade vacuum packer
user142019
it's a combobreaker
user142019
lol
I wonder how async can be fixed without leakage or complete reimplementation, though.
thread is easy to fix: just make a wrapper that joins on the destructor (or does nothing if detached).
But async is harder if not impossible.
Because you want to prevent the dtor of the future from running, yet you cannot prevent it from running because it may need to release resources.
Dec 17, 2012 15:49
It's a Honda 1.25hp 4-stroke centrifugal pump and a Hoselock 200W submersible electric pump. I still don't have enough suckage :(
You could fix it by spawning an extra thread to run the destructor in, but that is clearly a fucked up solution.
I honestly don't know anything about the Standard threading facilities
but I'm starting to think that's a good thing, not a bad thing.
Yea, sounds like you would have threaded in wrong territory
hehe
Oh, you can also fix std::async with a macro.
@TonyTheLion That may actually be the bestest fix. Sigh.
ewwww
macros
@R.MartinhoFernandes eh :(
Dec 17, 2012 15:56
Is __COUNTER__ standard?
Dammit.
Whatever.
#define ASYNC(...) auto THAT_ANONYMOUS_VARIABLE_MACRO_ANDREI_USED_IN_THE_STUPID_SCOPE_GUARD = std::async(__VA_ARGS)
lol
That's probably __LINE__ .
Dec 17, 2012 15:58
yeah, __LINE__ would be fine.
Nope.
ASYNC(blah); ASYNC(bleh);
you'll just have to disallow that
lol
__COUNTER__ is probably available everywhere except Hell++.
Macros ugliness
#define ASYNC(...) auto BOOST_PP_CAT(prefix, __LINE__) std::async(__VA_ARGS);
Dec 17, 2012 15:59
or use __COUNTER__ on supporting platforms and __LINE__ elsewhere
Someone should make a proposal to standardize it, because it is a de facto standard.
wait, couldn't you just add a new line?
#define ASYNC(...) blah \
then the next one will be on a new line
That does not change the __LINE__ because that is the original line number, not the one after expansion.
oh well
I am fine with __COUNTER__.
Dec 17, 2012 16:00
wait, you're telling me to ?
:P
Still, it's not a proper fix.
Not even the fucking macro is good enough.
It still blocks.
The only difference is that it does so at the end of the scope now.
If I want to block I can simply .get().
Blocking in the destructor takes that choice away.
Yeah, I'll just give up.
The macro does fix the problem of accidental non-parallelism.
> 214 points 1 hour ago*
why is the * there in some cases and others not (on Reddit)?
Dec 17, 2012 16:04
ah
C++ Builder with Clang? What the fuck
The world is really ending
> Remember, many webcams are equipped with an "on" light. Pay attention: If that light is on, but you're not using your camera, something may be amiss.
no shit?
@CatPlusPlus yes. Your hopes and dreams may finally come true.
I don't have any hopes and dreams
oh wow, you're worse off then first realized
I also still don't have any food
Why is that shop so far away
Dec 17, 2012 16:12
so you get some excercise :)
Online junk food it is
guys im trying to generate assembly with vs2012. I set Assembly Output to /FAcs under project's Configuration Properties > C/C++ > Output Files, but after the successful build, I cant find *.asm files in release directory. Any ideas?
@R.MartinhoFernandes Not capturing the return value of async is a choice.
@StackedCrooked What?
Dec 17, 2012 16:15
Intermediate files are kept in intermediate output directory, not the final output directory
That includes assembly listings
@StackedCrooked In case you are not aware, that choice means running sequentially.
@R.MartinhoFernandes auto a = async(...); vs async(...)
yeah that is set to Release\Tmp
Future joins on destruction
@StackedCrooked Yes, the latter is worthless.
Dec 17, 2012 16:16
@R.MartinhoFernandes Yeah, that's my point. It's the choice for running sequentally.
tbh
@StackedCrooked Wut.
joining on destruction is a dumb idea, I mean, the user can't use the value anymore, so why wait for it to be computed?
It's a bad choice, but it's not a bad design IMO.
I thought the choice for running sequentially was to call the function directly.
Dec 17, 2012 16:16
^
Why the fuck would I write std::async(std::launch::async, fun); when I can write fun();
async ever doing sequential execution is retarded
@CatPlusPlus, it creates the *.obj and other intermediate files there, except asm
That is a choice that should not be in the interface.
Then I don't know
You're doing something wrong
Read docs or something
Dec 17, 2012 16:18
The fact that you can easily get absolutely nothing out of std::async by accident is a clear indication of a bad design IMO.
Did you write your own async yet
No.
Was pondering how to fix it externally some minutes ago, but turns out you can't.
async sucks
 
Conversation ended Dec 17, 2012 at 16:19.