# better solution for this problem. - Unix

This is a discussion on better solution for this problem. - Unix ; I have two variables x and y; x is set to some constant value. and y will be incremented every time based on some event.Once the value of y equals x some operation will be done. we can implement the ...

# Thread: better solution for this problem.

1. ## better solution for this problem.

I have two variables x and y; x is set to some constant value.
and y will be incremented every time based on some event.Once the
value of y equals
x some operation will be done. we can implement the above scenario in
two different ways.

1. every time y is incremented check if it equals x and do_some_stuff
();

2. start a timer and wait for some reasonable time suppose 1 sec and
check if y equals x
and do_some_stuff (); the idea here is y will be incemented while
the timer is running and you can avoid
checking if y equals x for each and every time y is incremented.

Of the above two possible solutions, which one is the best and why?
i will implement the logic in C under Linux, in case if these things
matter.

thanks

2. ## Re: better solution for this problem.

> Of the above two possible solutions, which one is the best and why?

It depends entirely on factors that you haven't told us. For example:

Is the application intended to be real-time?

Is it acceptable for Y to be incremented several times before your program
notices? Or must your program know each and every time Y is incremented?

What is the "event" that increments Y? Is it an external real-world event,
like counting raindrops that fall on a sensor?

--
John Gordon A is for Amy, who fell down the stairs
gordon@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

3. ## Re: better solution for this problem.

On Aug 6, 11:39*pm, John Gordon wrote:
>
> > Of the above two possible solutions, which one is the best and why?

>
> It depends entirely on factors that you haven't told us. *For example:
>
> Is the application intended to be real-time?
>
> Is it acceptable for Y to be incremented several times before your program
> notices? *Or must your program know each and every time Y is incremented?
>
> What is the "event" that increments Y? *Is it an external real-world event,
> like counting raindrops that fall on a sensor?
>
> --
> John Gordon * * * * * * * * * A is for Amy, who fell down the stairs
> gor...@panix.com * * * * * * *B is for Basil, assaulted by bears
> * * * * * * * * * * * * * * * * -- EdwardGorey, "The Gashlycrumb Tinies"

The application is infact real time.
It is acceptable for Y to be incremented serveral times before my
program notices;
My program need not to know every time Y is incremented. It needs to
know only when Y equals X.
and Y will be incremented basing on some external world event like
other process writing some message on to the socket.

4. ## Re: better solution for this problem.

> The application is infact real time.
> It is acceptable for Y to be incremented serveral times before my
> program notices;
> My program need not to know every time Y is incremented. It needs to
> know only when Y equals X.

But what happens if Y becomes equal to X, and then gets incremented *again*

Sounds liker you might not be able to use a timer.

--
John Gordon A is for Amy, who fell down the stairs
gordon@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

5. ## Re: better solution for this problem.

On Aug 7, 9:51*am, John Gordon wrote:
>
> > The application is infact real time.
> > It is acceptable for Y to be incremented serveral times before my
> > program notices;
> > My program need not to know every time Y is incremented. It needs to
> > know only when Y equals X.

>
> But what happens if Y becomes equal to X, and then gets incremented *again*
>
> Sounds liker you might not be able to use a timer.
>
> --
> John Gordon * * * * * * * * * A is for Amy, who fell down the stairs
> gor...@panix.com * * * * * * *B is for Basil, assaulted by bears
> * * * * * * * * * * * * * * * * -- EdwardGorey, "The Gashlycrumb Tinies"

Y Can never go beyond X, so once the timer fires and if Y has actually
been incremented till X, do_some_stuff() will be called