Asynchronous and multi-threaded programming in MQL - page 35

 
Andrei Novichkov:

Why not actually read about the flag in the documentation? At https://en.cppreference.com . And examples with discussion on stackoverflow.com. I usually use these sources of information, and I advise you to do the same.

Why, then, do you want to join in the conversation if you are not responsible for your words? I was interested in your opinion, not the smart guys in the handbook. Get out of my way. I can read the docks without your instructions. And I don't need all this zoo of future/promise/async to call function in one thread.

 
Vict:

Why then would you come into the conversation if you don't answer for what you say? I was interested in your opinion, not the smart guys in the handbook. Get out of my way. I can read the docks without your instructions. And I don't need all this zoo of future/promise/async to call a function in one thread.

You're not making any sense. You don't know, I told you where to find the information. And it was my fault. Be a friend of books more often.
 
Andrei Novichkov:
You're not making any sense. You don't know, I told you where to find information. And it was my fault. Be a friend of books more often.

Apparently you don't know either. Why write about nothing? Maybe I don't know, what's the big deal? I asked for a normal opinion, he sent me off somewhere.

Blacklisted, comrade.

 
Vict:

Apparently you don't know either. Why write about nothing? Maybe I don't know, what's the big deal? I asked for a normal opinion, he told me to go somewhere.

Blacklisted, comrade.

I didn't send you anywhere, I didn't even think about it. I don't answer such questions well with my own words, so I wrote about documentation. Again, what is there to be offended about? But as you want, black, so black.
 
Andrei Novichkov:
I haven't sent you anywhere, I wouldn't dream of it. I'm bad at answering such questions in my own words, so I wrote about documentation. Again, what is there to be offended by? But as you want, black, so black.

Well the documentation on this is of little use

std::launch::deferred the task is executed on the calling thread the first time its result is requested (lazy evaluation)
I don't really understand why I need such a miracle, I can easily pass a pointer to a function into the thread I need and calculate it there without any async( std::launch::deferred).
 
Vict:

I don't really understand why I need such a miracle, I can easily pass a pointer to a function into a thread I need and calculate it there without any async( std::launch::deferred).

may be off-topic, but:

noticed that Microsoft examples are often written as self-documented code, so they write cumbersome constructs that can be expanded and replaced with the final value ( like, you see the code, and you get it all in one fell swoop ))) )

HH: In C# examples unfortunately it's not like that, several times I wrote C# with a belief that it is in fact an analogue of C++ with some propensityto use OOP, it turns out that it's not like that, it's not C++ at all, often you can not "get" to class fields without casting to a base class, that's why I have to use long unwieldy constructions, in general, parsing of ready-made libraries for C# is a real adventure!

 

Note, by default these two flags are applied together deferred | async, which removes the responsibility from the developer. We're talking about the main thread function here, yes, you can pass it anything, including a pointer to a function, or a functor, as an argument. And the deferred flag can even imply synchronous execution of the function. See, I told you, I'm bad at answering such questions in my own words.) You get muddled. Usually, you leave everything by default and don't bother with these flags, maybe it's not correct.

 
Igor Makanu:

HH: In C# examples unfortunately it's not like that, several times I wrote in C# with a belief that it's essentially an analog of C++ with some tendency to obligatoryuse OOP, it turns out that it's not like that, it's not C++ at all, often you can't "get" to class fields without casting to base class, that's why you have to use long cumbersome structures, in general parsing ready-made libraries for C# is a real adventure!

Well, MS has very good documentation on Spurs. Everything is explained in details. Can't complain.
 
Vict:

Well, the documentation on this is of little use

I don't really understand why I need such a miracle, I can easily pass a pointer to a function into a thread I need and calculate it there without any async( std::launch::deferred).
Well, for example, you need a function to calculate values with the current parameters on the stack, but not now and not in this scope. So, you create std::asinc, but, here's the problem, one of parameters is a reference or pointer to a global variable, but in calculation you won't need current value of this variable, but the one that will be later, that's why std::lounch::asinc and std::lounch::deferred bitmask are createdand you can pass value to function now and perform computation later.
 
Vladimir Simakov:
Well, for example, you need function to calculate values with current parameters on stack, but not now and not in this scope. So, you create std::asinc, but here's the problem, one of parameters is a reference or pointer to a global variable, but calculations will not need current value of this variable, but the one that will be later, that's why std::lounch::asinc and std::lounch:: deferred bitmasks are created and you can pass value to function now and perform calculations later.

So I can take a function I pass to async, bind arguments to it, and store it until it's time to call it (or send it to another thread). What difference does it make whether to store future or the output from std::bind()?

The only reasonable explanation I can think of is manual control over number of running threads in pool (if we don't trust default async|deferred) - for example, if system gets too busy, stop sending jobs with async flag, send deferred.

In general, I'm a bit disappointed by async() sluggishness, I'll create my own lightweight thread pool, it seems to me, it will be much faster.

Reason: