C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 30th, 2006, 09:55 AM
jaro jaro is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Posts: 35 jaro User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 6 h 16 m 44 sec
Reputation Power: 4
Send a message via Yahoo to jaro
Timed Function in C

Hi folks,

I was wondering (while a program is running) how to make a specific codes/methods to run on a pre-defined time.
Lets say every 2 minutes this codes/methods ,inside the program, would be executed while the said program is still running.

I try searching about this topic through the net , but most of the decent result that I got is about creating a timer.

I'm Using MVC6 and my OS is Win2k.

The program waits for incomming messages of sort.And It has to be a part of the same program.

Any kind help, may it be psuedo code or links, will be much appreciated.

regards,
jaro

Reply With Quote
  #2  
Old March 30th, 2006, 01:31 PM
ossinator ossinator is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Posts: 40 ossinator User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 6 h 11 m 12 sec
Reputation Power: 3
Send a message via ICQ to ossinator
As far as i understand your idea, you want your code to run, and, while it's running a timer to run, and every x seconds some function to be called.
If that's the case, threads are what you need.
There's a lot to be said about threads, you can find quite a lot about them on the net.
Basically the idea is that a thread is another process that's running along with your main program and can share resources with it.

So in your case you should start a thread with the timer and the calling of the function you want to execute every x seconds.

Some pseudo-code:

void do_program_logic();
void timer(void* passed_var);


int main()
{
volatile int passed_value = 5;
_beginthread(timer,0, &passed_value);
do_program_logic();
return 0;
}

There's a lot to be learnt for threads - how they work, how to pass variables to the new formed thread, what's the volatile keyword, and so on, it's really a complex matter, but i hope that gives you the idea what you have to look for on the internet


Hope that helps

Reply With Quote
  #3  
Old March 31st, 2006, 12:01 PM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 276 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 48 m 58 sec
Reputation Power: 4
Do we have a concept of threading in C??

Reply With Quote
  #4  
Old March 31st, 2006, 02:32 PM
ossinator ossinator is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Posts: 40 ossinator User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 6 h 11 m 12 sec
Reputation Power: 3
Send a message via ICQ to ossinator
as far as i know it is fully supported, i think there are a lot of *nix applications using threads, written in c, but i'm not fully sure.


Later edit:
I've cheked - it's fully supported, if your OS supports it. Unless you're writing for DOS or some other godforsaken os, it's supported.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Timed Function in C


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT