Asynchronous and multi-threaded programming in MQL - page 4

 
Dear forum users.

To work with multiple threads, you must first learn the essential difference between asynchrony, multithreading and multiprocess execution, because you can't even understand your logic in some places. First of all.

Secondly, the call to the external DLL still remains and who prevents you from implementing your own library with multiple threads and plugging it in?

Thirdly, for what tasks do you need multithreading in mql?

Not to mention the fact that you still have to learn the synchronization objects. Do you need it? If so, it is a very easy task to write a dll for you.
 
Roman:

So initializing inDLL_PROCESS_ATTACH: will be enough to call from mql program?

From mql program to call its functions located in dll.

 
Dmitry Fedoseev:

From the mql program to call its functions located in the dll.

And what is the problem with describing their signatures? You are pulling winapi through method signatures somehow, aren't you?
 
Andrey Pogoreltsev:
And what's the problem with describing their signatures? Don't you pull winapi somehow via method signatures?

I'm sorry, why describe them? And I'm sorry, I didn't pull anything))

 
Dmitry Fedoseev:

I'm sorry, why describe them? And I'm sorry, I didn't pull anything))

Sorry, I already thought you were asking.
 
Andrey Pogoreltsev:
Dear forum users.

To work with multiple threads, you must first learn the essential difference between asynchrony, multithreading and multiprocess execution, because you can't even understand your logic in some places. That's one.

Secondly, the call to the external DLL still remains and who's stopping you from implementing your own library with multiple threads and plugging it in?

Third, for what tasks do you need multithreading on mql?

Not to mention the fact that you still have to learn the synchronization objects. Do you need it? If you do, it is very easy for you to write a dll.

Andrey, I think everyone understands that asynchrony and multithreading are different things.
Since the CreateThread() function is described in the WinAPI inluder, it was assumed that threads could be used.
There are no functions similar to CreateTask() described in the IDE, so the assumption of possible asynchronous code writing disappears by itself.
Therefore, emphasis was placed on threads. However, as it turned out, the described functions are only WinAPI prototypes.
I repeat, the task was to use pure WinAPI and the described prototype CreateThread() was misleading. It is not said anywhere that these are prototypes.
All tasks are different, so I got to the asynchronous method and I believe that it is better to always write asynchronously or in threads,
And developed the habit of always writing asynchronously, will allow you to write fast programs, and raise your level as a specialist.
It's the basic principle of the developers themselves, the speed of execution of mql programs, is our everything!

It is a pity that mql has no such a feature,
I make a suggestion to the mql administration to develop standard mql functions for asynchronous programming,
since there are problems with threads and, above all, security.
For asynchronous mode I think there are no safety issues.

Example logic

Work out the implementation of EventLoop in mql.
create the MqlTask class
Declare the tasks as MqlTask object obj;
create task task = obj.CreateTask(MyFunc());
execute success = task -> Run();
pause execution success = task -> SleepMs(ms);
wait for success = task -> Wait(ms);
wait indefinitely success = task -> Wait(0);
remove the task after it executes delete task;

and all sorts of getStatuses to control it.

 
Roman:

Andrey, I think everybody understands that asynchronous mode and multithreading are different things.
The WinAPI's inluder contains the CreateThread() function and we had assumed that threads could be used.
Since there are no functions similar to CreateTask() described in the IDE, we should not consider possible asynchronous code writing.
Therefore, emphasis was placed on threads. However, as it turned out, the described functions are only WinAPI prototypes.
I repeat, the task was to use pure WinAPI and the described prototype CreateThread() was misleading. It is not said anywhere that these are prototypes.
All tasks are different, so I got to the asynchronous method and I believe that it is better to always write asynchronously or in threads,
And a developed habit to always write asynchronously, will allow you to write fast programs and raise your level as a specialist.
It's the basic principle of the developers themselves, the speed of execution of mql programs, is our everything!
Too bad there is no such a feature in mql, so I will make a suggestion to the mql team to develop a standard mql function
for asynchronous programming, since there are problems with the threads and, above all, security.
I think there are no security obstacles for asynchronous mode.
To work out the implementation of loop loops, and execute tasks in these loops.

Make up your mind whether you want to execute methods asynchronously or multithreaded. I work with sockets, for example, asynchronously from mql.

That these are signatures was immediately clear, what internal implementations are we talking about on a secure virtual execution environment? And how do you envision this?

And again. Those who know how to work with threads will easily write a DLL for it and do all the tasks there.

And yes, there are asynchronous methods in mql, for creating the same orders and working with network, if I'm not mistaken. What other methods do you need to make asynchronous? And what is the practicability of all of them?

Can you give me some cases where the speed of one thread is not enough?
 
Andrey Pogoreltsev:
Make up your mind whether you want to execute methods asynchronously or multithreaded. I, for example, work with sockets asynchronously from mql.

That these are signatures was immediately clear, what internal implementations are we talking about on a secure virtual execution environment? And how do you envisage this?

And again. Those who know how to work with threads will easily write a DLL for it and do all the tasks there.

And yes, mql has asynchronous methods to create the same orders and work with network, if I'm not mistaken. What other methods do you need to make asynchronous? And what is the practicality of it all?

Can you give us some cases where the speed is not enough to work in one thread?

In order to determine what is possible to use in mql and what is forbidden.
CreateThread() was found in the inludes, so I thought it was possible to work with threads.
But as it turned out threads are forbidden, so the choice falls on async, but how to use async in mql is also not clear.
Yes, that's exactly the problem with sockets. The help says that no more than 128 sockets can be created, which limits getting information on American stocks, for example.
And even those 128 sockets it's not clear how to convert it into asynchronous mode and avoid delays in processing incoming data.
That's why I had to search for solution to the problem in another way,but I wanted to solve it in pure WinAPI, without any self-written dll.
And how to work asynchronously in mql it's interesting, if you have any working examples, it would be good to discuss them, if you can share the information.
But the standard asynchronous methods in mql help I have not seen.

 
Roman:

In order to determine what is possible to use in mql and what is forbidden.
I found CreateThread() in the code's injectors, so I thought I could handle threads.
But as it turned out threads are forbidden, so the choice falls on async, but how to use async in mql is also not clear.
Yes, that's exactly the problem with sockets. The help says that no more than 128 sockets can be created, which limits getting information on American stocks, for example.
And even those 128 sockets it's not clear how to convert it into asynchronous mode and avoid delays in processing incoming data.
That's why I had to search for solution to the problem in another way,but I wanted to solve it in pure WinAPI, without any self-written dll.
And how to work asynchronously in mql it's interesting, if you have any working examples, it would be good to discuss them, if you can share the information.
But the standard asynchronous methods in mql help I have not seen.

If you want to work asynchronously with sockets via winapi, use winsock2.

TryWSARecv and WSASend with OVERLAPPED and WSAEVENT.

Then WaitFor...
 

I read the smart participants and I wonder...

What's the point of all these gimmicks?

When in MQL would the multi-threading be so terribly needed? To me, the only use would be strategy testing, which is implemented in the standard way.

Ideally, it might make sense to run several WebRequests, but I don't think multi-threading is needed at all.

What tasks require multithreading in the first place?