LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-25-2007, 12:26 AM   #1
scanner
LQ Newbie
 
Registered: Jul 2006
Posts: 28

Rep: Reputation: 15
About POSIX timer


For POSIX timer, we can get a timer ID by calling timer_create. After checked man, timer ID may be any value including zero. But when our guy mistake to call timer_delete with zero as timer ID, crash happen with timer_delete, as core dump file. Can anyone confirm the issue? In addition, we are using tool-chain v4.1.
 
Old 04-25-2007, 06:39 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 34
The kernel uses an integer value to uniquely identify each new timer.
It starts counting and goes on. It is theoretically possible for the number to rollover, ie., 0xffffffff -> 0. I do not know if Linux kernels support this. Plus, this would require using a LOT of timers on a system that was up for a very long time.

If your code tries to access a non-existent timer, it will dump core. Is that what you're asking? You do realize that what you describe is a coding error, not a kernel problem.
 
Old 04-26-2007, 12:53 AM   #3
scanner
LQ Newbie
 
Registered: Jul 2006
Posts: 28

Original Poster
Rep: Reputation: 15
Thumbs up

Quote:
Originally Posted by jim mcnamara
The kernel uses an integer value to uniquely identify each new timer.
It starts counting and goes on. It is theoretically possible for the number to rollover, ie., 0xffffffff -> 0. I do not know if Linux kernels support this. Plus, this would require using a LOT of timers on a system that was up for a very long time.

If your code tries to access a non-existent timer, it will dump core. Is that what you're asking? You do realize that what you describe is a coding error, not a kernel problem.

First thanks for your reply.

In addition, as your reply, zero may be a timer ID. Am I right?

So, as man timer_delete, if a invalid timer ID is inputted like my case, a error code should be returned instead of crash. Actually I mistook to input zero as timer ID to timer_delete, i.e. I used a invalid timer ID, so a error code should be returned in such case. Is my understanding correct?
 
Old 04-26-2007, 01:54 AM   #4
Kristofer
LQ Newbie
 
Registered: Nov 2005
Location: Sweden
Distribution: Slackware
Posts: 20

Rep: Reputation: 0
No

Hi scanner

Lets look at the following to start with:

int timer_create(clockid_t clockid, struct sigevent *restrict evp, timer_t *restrict timerid);

"If the call succeeds, timer_create() shall return zero and update the location referenced by timerid to a timer_t, which can be passed to the per-process timer calls. If an error occurs, the function shall return a value of -1 and set errno to indicate the error. The value of timerid is undefined if an error occurs."

It's the return value of timer_create you have to check before you try to use the timerid in timer_delete(), because if you pass an invalid timer id to timer_delete it might/will crash, not return an error.

Code:
pseudocode
int retvalue timer_create(..., ..., &timerid);
if(retvalue == -1)
{
   print the error
   maybe exit
}
else
{
  do something with the timer
  ...
  time to delete the timer
  retvalue = timer_delete(timerid);
  if(retval == -1)
  {
    print error message, e.g "Failed to delete timer"
  }
}
/Kristofer

Last edited by Kristofer; 04-26-2007 at 02:19 AM.
 
Old 04-26-2007, 02:24 AM   #5
scanner
LQ Newbie
 
Registered: Jul 2006
Posts: 28

Original Poster
Rep: Reputation: 15
Thumbs up

So when EINVAL will be returned by timer_delete???

EINVAL : The timer ID specified by timerid is not a valid timer ID.
 
Old 04-26-2007, 03:37 AM   #6
Kristofer
LQ Newbie
 
Registered: Nov 2005
Location: Sweden
Distribution: Slackware
Posts: 20

Rep: Reputation: 0
Yes

Yes according to man, timer_delete should return EINVAL, not crash (did you try to do anything else than timer_delete with the invalid timer?), (note: I haven't tried it myself).

Here is a good example of how to interface with the timer_* functions
http://www.google.com/codesearch?hl=...elete/1-2.c#a0

/Kristofer
 
  


Reply

Tags
timer


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
posix timers mailsteam Programming 7 05-18-2007 11:32 PM
Multimedia timer (SMP friendly timer) bigqueso Linux - Kernel 0 03-15-2007 03:49 PM
Posix Tutorials! twirl Programming 1 09-17-2005 04:04 AM
Posix arunshivanandan General 1 05-19-2003 08:07 AM
Posix? justiceisblind Linux - Newbie 2 03-11-2002 08:04 PM


All times are GMT -5. The time now is 01:04 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration