By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,501 Members | 2,797 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,501 IT Pros & Developers. It's quick & easy.

help me in threads

P: 16
i work in VC++ win32 application
i want to creat 2 threads th1 and th2
th1 will run th2 and wait 10 second and increment a counter
th2 will run 1 second and increment another counter
during the 1 second of th2 it will run a small functions according to counters c1,c2 values
each time th2 interrupt the running small programs to increment c2 when it come back the interrupted program should incremented from its last position not to start over again.i used beginthread method but the timing was not correct at all and here is my code:
Expand|Select|Wrap|Line Numbers
  1. /****************************************/
  2. void dispatcher()
  3. {
  4.  function1();
  5.  function2();
  6.  .
  7.  .
  8.  .
  9.  .
  10.  .
  11.  function();
  12. }
  13. void subframe(void *arg )
  14. {
  15.  
  16.     while(1)
  17.     {
  18.      cout<<"\n Start SubFrame no"<<FScount.sub;
  19.          _beginthread(dispatcher,0,NULL);
  20.        wait(10000);
  21.       sub++;
  22.         }
  23. }
  24. /********************************************/
  25. void mainframe(void *arg )
  26. {
  27. while(1)
  28.  {
  29.   cout<<"\n ==Starting Frame No."<<FScount.frame<<"==";
  30.   _beginthread(softInterrupt,0,NULL);
  31.    wait(30000);
  32.    FScount.frame++;
  33.  }
  34. }
  35. /********************************************/
  36. void main(void)
  37. {
  38.     _beginthread(mainframe,0,NULL);
  39. }
  40.  
Oct 17 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.