FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log inLog in 


To sleep or not to sleep.

Post new topic   Reply to topic    discuss.visual-prolog.com Forum Index -> Visual Prolog Tips & Samples
View previous topic :: View next topic  
Author Message
Josť A. Becerril



Spain
Joined: 22 Apr 2000
Posts: 127

PostPosted: 22 Sep 2010 22:22    Post subject: To sleep or not to sleep. Reply with quote

Sometimes we have to wait for an external process to finish in order to continue with our code execution. Since it is external, processevents is no good, and sleep is the only solution. The problem is: sleep for how long? Sometimes an external or uncontrolled process depends on network speed, or different processors speed. We donít want to sleep for too long or too little. This is my simple solution:


    ...
uncertainProcess()
...

  facts
      sleeping:integer:=0.
      predicates
      increaseSleep:().
      clauses
      increaseSleep():-
      sleeping<500,
      sleeping:=sleeping+10,  
      uncertainProcess(),!.
     
      increaseSleep():-
      stdio::write("uncertainProcess failed"),!.
       
     
     predicates
     uncertainProcess:().
     clauses
     uncertainProcess():-
     programControl::sleep(sleeping),
     file::existfile("myfile.txt"),
     stdio::write("I have seen the file"),!.
     
     uncertainProcess():-
      increaseSleep(),!.

Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    discuss.visual-prolog.com Forum Index -> Visual Prolog Tips & Samples All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum