I'm sorry guys. I was thinking that each EA run in the same program, but in different Threads. But I realize that each one is a program.
Well, If I am right, I won't need MUTEX to control critical regions.
Thanks
Each EA runs in his own thread.
If you want a mutex, you have to code it, what's the problem ?
Because to implement a mutex, I need to call a special function that runs a System Call on OS. But I don't know if this function exists in MQL5.
After I sent my question here, I realized that each EA is running in different Threads. So, I think I don't need to control critical regions, because they are separated for each EA. Am I right?
Because to implement a mutex, I need to call a special function that runs a System Call on OS. But I don't know if this function exists in MQL5.
After I sent my question here, I realized that each EA is running in different Threads. So, I think I don't need to control critical regions, because they are separated for each EA. Am I right?
I already confirm that each runs in his own thread.
What is "critical regions" ?
What is "critical regions" ?
- en.wikipedia.org
http://en.wikipedia.org/wiki/Critical_section
lol.
This was not my question, what is your critical section, concretely.
lol.
This was not my question, what is your critical section, concretely.
Let's imagine that I have a counter of unique identificators for different market makers that I trigger, in the same EA.
I can trigger a new market maker in two different functions:
- OnTradeTransaction;
- OnTimer.
Both are called by MT5, when different events come.
In my case, both need to get the next unique ID for execute a market maker.
In this context, my critical secction is something like this:
int nextMarketMakerId(){ return ++_nextMMId; }
In java, for example, I could emulate a mutex using the reserved word "synchronized" like
public synchronized int nextMarketMakerId(){ return ++_nextMMId; }
In C, I could call the function pthread_mutex_lock of pthread.h library like
#include <threads.h> static mtx_t cs_mutex; void nextMMId( void ){ int result = -1; mtx_lock( &cs_mutex ); result = ++_nextMMId; mtx_unlock( &cs_mutex ); return result; }
And my question is about this. Maybe it can be divide in two questions:
- In MQL5, Can the MT5 call the two functions (OnTradeTransaction and OnTimer) at the same time? Or Will they be called without time intersection?
- How can I use a mutex structure in MT5.
Do you get it?
Thanks!
Let's imagine that I have a counter of unique identificators for different market makers that I trigger, in the same EA.
I can trigger a new market maker in two different functions:
- OnTradeTransaction;
- OnTimer.
Both are called by MT5, when different events come.
In my case, both need to get the next unique ID for execute a market maker.
In this context, my critical secction is something like this:
In java, for example, I could emulate a mutex using the reserved word "synchronized" like
In C, I could call the function pthread_mutex_lock of pthread.h library like
And my question is about this. Maybe it can be divide in two questions:
- In MQL5, Can the MT5 call the two functions (OnTradeTransaction and OnTimer) at the same time? Or Will they be called without time intersection?
No, they cannot be called at the same time. 1 EA use 1 thread, all the code is executed in 1 thread.
A program receives only events from the chart it runs on. All events are processed one after another in the order they are received. If a queue already has a NewTick event, or this event is currently being processed, then the new NewTick event is not placed in the queue of the MQL5 program. Similarly, if ChartEvent is already enqueued, or this event is being processed, no new event of this kind is enqueued. The timer events are handled the same way if the Timer event is in the queue or being handled, the new timer event is not enqueued.
- How can I use a mutex structure in MT5.
You don't need a mutex here. You will eventually need it if your code is accessing something from different EA. For example, global variables of the terminal or a file, etc...
If you really need a mutex, I am sure you will be able to imagine a solution
Many thanks angevoyageur.
:)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi guys,
I need to use a semaphore mutex in my MQL5 code.
Do the language provide us this possibilite without to use a DLL?
Regards