Click here to Skip to main content
15,794,475 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am trying to change an application which is time driven to be event driven

The original application uses the timeSetEvent function which creates a thread for the timer and every time the delay duration of the timer is reached the callback procedure is activated

I want to signal the thread of the timer so it would activate the callback before the
the delay duration is reached

Is there a way to change the timer thread in order to add an event
to be waited to and not just the timer?

Is there any other solution to this problem?

Thanks

dj

What I have tried:

Calling the callback from outside - but its a big change of the original code
Posted
Updated 29-Apr-18 0:24am

1 solution

You did not told us about the kind of your threads (like Windows theads or Linux pthread).

But I assume that your thread is already checking for events like stop (when terminating the application) or for starting and resetting the timer. If so, just implement another event that simply calls the callback function when triggered.

If not, I suggest to do so at least for stopping. When your application terminates it should also stop all child threads. Otherwise those would run until returning by themself.

With Windows use WaitForSingleObject resp. WaitForMultipleObjects. With pthreads use pthread_cond_wait or pthread_cond_timedwait. You can also use the timeout value of those functions to implement the timer (if not already doing so).

Implementing a stop event is usually covered by tutorials about a specific thread type. Once using such, adding another event for other purposes is quite simple.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900