is there anyway to know whether an expert advisor is currently sleeping or not?

 
Hello people
I would really appreciate if anybody could tell me any function which could be used to know whether an expert advisor is slept or not from another expert advisor as a mean of process synchronization.
I look forward for your responses.
Regards,
John
 
The EA could use GlobalVariableSet() to inform the outside it is going to sleep or has woken up.
 
Yeah, but if u put
{
GlobalVariableSet();
(*)
sleep();
}
in the expert advisor 1,
then some other expertadvisor 2 can be run in the middle (*) between GlobalVariableSet and sleep of the expert advisor 1. So, even if you check the value of the corresponding globalvariable from another expertadvisor 2, you would still not know if the expert advisor 1 is already sleeping or not. For this, I think the reply below still does not answer my question. I still apreciate ur interest.
Thanks anyways.
 
Use a different GlobalVariable for each sleeping code unit.

Would that not work?
 
I'm afraid I have not made clear enough the problem I explained before which is the following one:

execution order for two expert advisors:

time Expert
advisor

steps

1 EA1 globalvariableSet("A",5);
2 EA2 varA = globalvariableget("A");
3 EA2 if (varA == 5) then //it means that expert advisor1 is slept
4 EA2 ....
5 EA2 ....
6 EA2 ....
7 EA1 sleep();

As we can see, expert advisor 2 would think that expert advisor1 is already sleeping in the step number 3. However
we can see, expert advisor1 does not start sleeping until step 7. That is why I am asking for an mql4 instruction which would let us know if another expert advisor is already sleeping or not.
Thanks anyways Phy. May be, some more people will have some new ideas to solve my question which is still not solved.
 
* wonders what you are trying to accomplish
 
I don't think Code#2 will get any processing time to check the status of the variable until Code#1 enters sleep.

But I could be wrong.
 
I have seen with my own eyes that it happens, that is to say, the cpu scheduler some times takes the expert advisor 1 out from the cpu to run expert advisor2 and after that it takes expert advisor 1 again. But nobody can know what the scheduler is gonna do each time you run your program. Thks Phy anyways, it's ok. I just mean, that some mql4 developer from could see this post and may be they could think about implementing a function like "isawake?" or sth like that to know if another expert if sleeping or not because in my point of view, any programming language which has the sleep() function should have another function to know if some execution thread is sleeping or not.
 
Yeah. What if it just has its eyes closed, and is really awake?
 
jorgecanta47, what you need to do is implement a double lock pattern. It is a standard software pattern that software developers use.

Once you have a lock you can do what ever you want.

Here is what i think it might look like in mt4 using global variables (Note: i did not compile or test this, i just tapped it out so use at your own risk)


int MaxGlobalVarLockSeconds = 30;

int start()
{

	double lock = GetLock();
	if(lock > 0)
	{
	  Print("In Lock, so doing stuff");
	
	  ReleaseLock(lock);
	}
}



double GetLock()
{
   double lock;
   lock = 0.0;
   double tryLock = GetTickCount();

   
   //make sure the lock exists
   GetGlobalLock(0.0, CyclingKey);
   
    
   if(IsStopped() == false)
   {
      if(GlobalVariableSetOnCondition("lock",tryLock,0)==true)
      {
         lock = tryLock; 
      }
      
      if(GetLastError()==ERR_GLOBAL_VARIABLE_NOT_FOUND)
      {
         GetGlobalLock(0.0, CyclingKey);
         lock = 0.0;
      }
      else if(lock == 0.0)
      {
         //check for expired lock
         double currentLock = GlobalVariableGet(lock);
         if(tryLock - currentLock > MaxGlobalVarLockSeconds * 1000)
         {
            GlobalVariableSetOnCondition("lock",0.0, currentLock);
            Print("Current lock expired. Try to get the lock again.");
         }
      }
   }
   
   return(lock);
}

	

bool ReleaseCycleLock(double lock)
{
   GlobalVariableSetOnCondition("lock", 0, lock);
}


double GetGlobalLock(double defaultValue = 0.0)
{
   string settingName = "lock";
   if(GlobalVariableCheck(settingName)==false)
   {
      GlobalVariableSet(settingName, defaultValue);
      return(defaultValue);
   }
   else
   {
      return(GlobalVariableGet(settingName));
   }
}


void SetGlobalLock(double value, string key = "")
{
   GlobalVariableSet("lock", value);
} 
Reason: