Asynchronous and multi-threaded programming in MQL - page 33

 
Roman:

I like everything )) different approaches to understand and then choose the one that makes more sense to me and fits the requirements, it's simple.

The whole world works with DLL, with the wonders of ICL only a group of sectarians who think it is the highest competence.
 
Yuriy Asaulenko:
The whole world works with DLL, with the miracles of ICL only a group of sectarians who think it is the highest competence.

That's hilarious, and I couldn't agree more ))))
Well gone to read the manuals and think about the options on offer.
Thanks to all who really do not flub, suggested various solutions.
Now there is much to choose from.

 
It reminds me of an old joke, by the way.
International Medical Congress. Report from the Russian delegation - "Removal of tonsils through the anus".
We read it. Followed by questions from the audience.
- We admire the skill and achievements of Russian surgery. But why through the back passage?
- That's how we all do it.
 
Vict:

I understand correctly that Futures and Async are standard only for C++ ?
Isn't there a similar library in C ?

 
Roman:

I understand correctly that Futures and Async are standard only for C++ ?
Isn't there a similar library in C ?

Right. Cish std also has multi-threading support https://en.cppreference.com/w/c/thread

ZS: you could also read the book "c++ concurrency in action" by anthony williams. For example, in chapter 9 he writes thread pool.

Thread support library - cppreference.com
  • en.cppreference.com
If the macro constant is defined by the compiler, the header and all of the names listed here are not provided. Function names, type names, and enumeration constants that begin with either , , , or , and a...
 
Vict:

Right. Cish std also has multi-threading support https://en.cppreference.com/w/c/thread

HH: you could also read the book "c++ concurrency in action" by anthony williams. For example, in chapter 9 he writes thread pool.

Didn't notice the See also link at the bottom of the page ))
Got it,std::thread is in C, butstd::async is not ((

Just reading this book now )) Parallel C++ programming in action, Anthony Williams.
The book is in the attachment,
async starts at chapter 4, pretty easy to read.
And Kurt Ganteroth, in his book Optimizing C++ Programs, claims that it's 14 times more expensive to create threads than to use std::async.
That's why I originally wanted to use async, but I didn't know much about threads in C/C++ either,
so ifthreads are more expensive, they fall off for use anyway.
But it turns out that in C,std::async does not exist((


 
Roman:

Didn't notice the See also link at the bottom of the page ))
Got it,std::thread is in C, but std:: async is not ((

Just reading this book now )) Parallel C++ programming in action, by Anthony Williams.
If you're interested the book is in the attachment, async starts at chapter 4, pretty easy to read.
And Kurt Ganteroth, in his book Optimizing C++ Programs, states that it is 14 times more expensive to create threads than to use std::async.
That's why I originally wanted to use async, but I didn't know much about threads in C/C++ either,
so ifthreads are more expensive, they're not worth using anyway.
But it turns out that in C,
std:: async does not exist ((

A thread isn't more expensive, it's just a lower-level tool you can make anything from. You can make your own simple thread pool on "expensive threads" - an hour of writing (or take a ready-made lib).

creating threads is 14 times more expensive than using std::async.

Maybe if there's a thread pool inside async, but that's not always the case https://stackoverflow.com/questions/15666443/which-stdasync-implementations-use-thread-pools.

As a result, async is such a black, uncontrollable box. I don't urge you to write your own pool, if you feel comfortable with async, fine.

ZS: there were rumours that async was going to be removed from c++17.
Which std::async implementations use thread pools?
Which std::async implementations use thread pools?
  • 2013.03.27
  • KnowItAllWannabeKnowItAllWannabe 5,31455 gold badges3434 silver badges7676 bronze badges
  • stackoverflow.com
One of the advantages of using instead of manually creating objects is supposed to be that can use thread pools under the covers to avoid oversubscription problems. But which...
 

Async can be executed synchronously, there is a flag for it. I think thread pooling on pluses is complicated and only makes sense to write it in case of extreme necessity. You'd better take a look at Sharp, at that thread pooling.

I would also recommend "Scott Meyers: Efficient and Modern C++". 2016, easy to read, like a blockbuster. I've attached the archive below. He has an interesting chapter on threads. And in general, Meyers should be read, because you have to )))

 
Andrei Novichkov:

I think thread pooling on the pros is tricky and only makes sense if it's absolutely necessary.

Don't make it any harder than it needs to be. If you don't want to write it yourself, you can easily take a ready-made one, a quick search here https://github.com/vit-vit/ctpl. And it is something less predictable, unlike async (which is often criticized).

vit-vit/CTPL
vit-vit/CTPL
  • vit-vit
  • github.com
More specifically, there are some threads dedicated to the pool and a container of jobs. The jobs come to the pool dynamically. A job is fetched and deleted from the container when there is an idle thread. The job is then run on that thread. A thread pool is helpful when you want to minimize time of loading and destroying threads and when you...
 
Vict:

Don't make it any harder than it has to be. If you don't want to write it yourself, you can easily get a ready-made one, here is a quick search https://github.com/vit-vit/ctpl. And it is something less predictable, unlike async (which is often criticized).

Nope, don't feel like it )))))) But a cursory search is also, umm, fraught. I've come across a lot of junk on github. But I'm interested in another one, are there any tasks that would really require thread pooling? Not just create a thread, forget it and wait until it finishes, but just pool it like Williams describes? It seems to be an example of an ATM there, if I'm not mistaken - what task could justify such a miracle judo? I can't think of such a task yet. And why don't you really look at ThreadPool where everything is already done, there is documentation and examples.