LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-19-2017, 01:01 PM   #1
reha
LQ Newbie
 
Registered: Jun 2016
Posts: 2

Rep: Reputation: Disabled
Question How to apply 2 timers on a Node..???


Dear all,

I am interested in applying two timers(T1 & T2) on a node.

1. As per the functionality of my protocol, the timer 'T1' is only called once at the start of the simulation.
2. The timer 'T2' is called again and again during the simulation.

However, till now, I am unable to implement both timers T1 & T2 together. In this context, my questions are:

Kindly is there any possible way of implementing both timers T1 & T2 together...?

Kindly is there any way of deactivating the timer T1 when I realize that its task is over that shall help me to activate T2 later on...?

Also, I am using NS-2.31 with MACNG based implementation for my simulation. Thank you...

Last edited by reha; 10-19-2017 at 01:03 PM.
 
Old 10-19-2017, 01:36 PM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
wouldn't you be better off starting your first timer then whatever time between its stopping and starting the other timer devise a method to all it as soon as your start timer has quit. something like this?
Code:
#include <iostream>
#include <ctime>
#include <cstdlib>

void start_one(int a);
void start_two(int a);
int main()
{
start_one(2);

// start it here or call in as soon as the first one stops
 //start_two(5);

return 0;
}

// seconds laps time in prams


void start_one(int a)
{
 clock_t startTime = clock(); //Start timer
 double secondsPassed;
 double secondsToDelay = a;
 bool flag = true;

//call here to fire imminently then stay until
// times up
 while(flag)
  {
   secondsPassed = (clock() - startTime) / CLOCKS_PER_SEC;
   if(secondsPassed >= secondsToDelay)
    {
		// put in here what you want ran to 
        // to start after delay
	std::cout<< " timer one"<<std::endl;
	flag = false;
     secondsPassed  = 0;
     startTime = clock();
    }
  }
  start_two(5); // here as soon as this one is over with it will start the other one
}



void start_two(int a)
{
 clock_t startTime = clock(); //Start timer
 double secondsPassed;
 double secondsToDelay = a;
 bool flag = true;



 while(flag)
  {
   secondsPassed = (clock() - startTime) / CLOCKS_PER_SEC;
   if(secondsPassed >= secondsToDelay)
    {
	// put in here what you want ran
		std::cout<< " timer two"<<std::endl;
    // no resetting flag it will run forever
    // fires every x sec elapse time
     secondsPassed  = 0;
     startTime = clock();
    }
  }
}
or just call both to start at the same time, but I am guessing this is causing conflict if it is
controlling the same thing at the same time.

Last edited by BW-userx; 10-19-2017 at 01:50 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
rhel 2 node cluster: resources do not move to second node when node halted tapuhi Linux - Software 1 03-01-2015 10:41 AM
ACE REACTOR timers or POSIX timers sbauer72 Programming 4 02-26-2012 04:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration