Solved

F*S*M T*ime

Posted on 2008-10-13
2
165 Views
Last Modified: 2012-05-05
I want to implement an F*S*M  and when a "job" is at one state for some time ,for example 1 min and then go to other state.The problem is that i don't know how to implement the time(clock) of this  system.
0
Comment
Question by:Tom211
  • 2
2 Comments
 
LVL 53

Expert Comment

by:Infinity08
ID: 22709389
You want a delay of 1 minute ?

You can use the standard library for that, something like below (note that it's a busy wait, so likely not the preferred way to do it).

Or you can use platform dependent functionality, like sleep or usleep (Linux), Sleep (Windows), ...
What platform are you on ?
time_t tstart = time(0);

time_t tend = time(0);

while (difftime(tend, tstart) < 60.0f) {   // <--- one minute

  // busy wait

}

Open in new window

0
 
LVL 53

Accepted Solution

by:
Infinity08 earned 50 total points
ID: 22709394
The code sample should have been like this of course (otherwise you'd likely have an infinite loop) :
time_t tstart = time(0);

time_t tend = time(0);

while (difftime(tend, tstart) < 60.0f) {   // <--- one minute

  // busy wait

  tend = time(0);

}

Open in new window

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now