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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
04-25-2007, 12:26 AM
|
#1
|
|
LQ Newbie
Registered: Jul 2006
Posts: 28
Rep:
|
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.
|
|
|
|
04-25-2007, 06:39 AM
|
#2
|
|
Member
Registered: May 2002
Posts: 964
Rep:
|
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.
|
|
|
|
04-26-2007, 12:53 AM
|
#3
|
|
LQ Newbie
Registered: Jul 2006
Posts: 28
Original Poster
Rep:
|
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?
|
|
|
|
04-26-2007, 01:54 AM
|
#4
|
|
LQ Newbie
Registered: Nov 2005
Location: Sweden
Distribution: Slackware
Posts: 20
Rep:
|
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.
|
|
|
|
04-26-2007, 02:24 AM
|
#5
|
|
LQ Newbie
Registered: Jul 2006
Posts: 28
Original Poster
Rep:
|
So when EINVAL will be returned by timer_delete???
EINVAL : The timer ID specified by timerid is not a valid timer ID.
|
|
|
|
04-26-2007, 03:37 AM
|
#6
|
|
LQ Newbie
Registered: Nov 2005
Location: Sweden
Distribution: Slackware
Posts: 20
Rep:
|
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
|
|
|
|
| Thread Tools |
Search 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
HTML code is Off
|
|
|
All times are GMT -5. The time now is 09:01 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|