Can I use select instead Sleep?
-
I need my program sleep 1 microsecond, but Sleep() can not do this. So, can I use select() instead Sleep() to do this?
timeout.tv_sec=0; timeout.tv_usec=1; FD_ZERO(&readfd); ret=select(0,&readfd,NULL,NULL,&timeout);
It's have any problem or not? -
The Windows multimedia timers[^] might be useful
Actually, they won't help. The OP wants resolution in terms of microseconds!
It is a crappy thing, but it's life -^ Carlo Pallini
-
Actually, they won't help. The OP wants resolution in terms of microseconds!
It is a crappy thing, but it's life -^ Carlo Pallini
-
I was particularly avoiding in providing any possible solution to him, because the OP's approach has a fundamental flaw (introducing 'artificial' delays in his code). And to answer you, NO, multimedia timers are neither going to provide resolutions any closer to microseconds! Not under Windows.
It is a crappy thing, but it's life -^ Carlo Pallini
-
I was particularly avoiding in providing any possible solution to him, because the OP's approach has a fundamental flaw (introducing 'artificial' delays in his code). And to answer you, NO, multimedia timers are neither going to provide resolutions any closer to microseconds! Not under Windows.
It is a crappy thing, but it's life -^ Carlo Pallini
Rajesh R Subramanian wrote:
And to answer you, NO
I do not claim that they have a resolution of microseconds. But they have a resolution which is considerably higher than the standard timer so they come closer to the goal. Sure they don't reach it, but being closer is better than .. well.. not being closer
-
Rajesh R Subramanian wrote:
And to answer you, NO
I do not claim that they have a resolution of microseconds. But they have a resolution which is considerably higher than the standard timer so they come closer to the goal. Sure they don't reach it, but being closer is better than .. well.. not being closer
harold aptroot wrote:
But they have a resolution which is considerably higher than the standard timer so they come closer to the goal. Sure they don't reach it, but being closer is better than .. well.. not being closer
Well, why don't you understand? Do I have to say again? It is NOT closer to the goal. The goal itself, is unachievable. Windows does not support such things. Not to mention the OP's approach is flawed. For an OS to provide real-time functionality, it would require a very strong knowledge of the underlying hardware (including how fast each and every device is, how fast is the bus, the processor, how will they behave under specific conditions, etc.,). However, Windows was designed to support a wide variety of hardware, which means that the OS cannot practically have a deep knowledge of each and every hardware device that it may have to work with. So they had to compromise on this part. Is that you down-voting? Why? Because I don't agree with your comment? Well, your comment is WRONG.
It is a crappy thing, but it's life -^ Carlo Pallini
-
harold aptroot wrote:
But they have a resolution which is considerably higher than the standard timer so they come closer to the goal. Sure they don't reach it, but being closer is better than .. well.. not being closer
Well, why don't you understand? Do I have to say again? It is NOT closer to the goal. The goal itself, is unachievable. Windows does not support such things. Not to mention the OP's approach is flawed. For an OS to provide real-time functionality, it would require a very strong knowledge of the underlying hardware (including how fast each and every device is, how fast is the bus, the processor, how will they behave under specific conditions, etc.,). However, Windows was designed to support a wide variety of hardware, which means that the OS cannot practically have a deep knowledge of each and every hardware device that it may have to work with. So they had to compromise on this part. Is that you down-voting? Why? Because I don't agree with your comment? Well, your comment is WRONG.
It is a crappy thing, but it's life -^ Carlo Pallini
You think it is not closer. But it is. He's never going to reach the goal, but a better resolution takes him closer to his goal. Just because you can not get there doesn't mean you can not get closer. And yes I gave you a 3, not because you disagree but because You are the one who is partically wrong. It would be closer to his goal. It's like trying to reach 0K (zero Kelvin) really - you won't reach it, but you can get a lot closer than your kitchen freezer (which would be the normal timer in this analogy) So why won't I understand? Because it isn't true in the first place. edit: and here's an other one: suppose someone says "I want to get positive infinity using an integer! I am using uint32 now but it won't go high enough", well of course he can't reach it, but he could get closer using an uint64. It could be that he didn't really need infinity but just "something really high" and that it would help him anyway, just as in this case the OP may not know that multimedia timers exist and they may be good enough for what he's doing - who knows? At least he will be better off knowing that they exist.
-
You think it is not closer. But it is. He's never going to reach the goal, but a better resolution takes him closer to his goal. Just because you can not get there doesn't mean you can not get closer. And yes I gave you a 3, not because you disagree but because You are the one who is partically wrong. It would be closer to his goal. It's like trying to reach 0K (zero Kelvin) really - you won't reach it, but you can get a lot closer than your kitchen freezer (which would be the normal timer in this analogy) So why won't I understand? Because it isn't true in the first place. edit: and here's an other one: suppose someone says "I want to get positive infinity using an integer! I am using uint32 now but it won't go high enough", well of course he can't reach it, but he could get closer using an uint64. It could be that he didn't really need infinity but just "something really high" and that it would help him anyway, just as in this case the OP may not know that multimedia timers exist and they may be good enough for what he's doing - who knows? At least he will be better off knowing that they exist.
harold aptroot wrote:
At least he will be better off knowing that they exist.
Fine, he'll know that such a thing exists. That's the only point I can take. But, I won't take the "it's closer to the goal" codswallop.
harold aptroot wrote:
And yes I gave you a 3, not because you disagree but because You are the one who is partically wrong. It would be closer to his goal.
Now, you're being ridiculous. How is it closer? He's trying to achieve something that would require an RTOS, but is doing that task on Windows. So, how is any approach going to be closer to the goal? Not only you don't know about the subject, but you're also down-voting because you think that I'm wrong. How long have you been doing C++ or programming Windows to say that using a multimedia timer can be closer to make Windows behave like an RTOS? I'd assume that you're a teenager, have never worked on any professional project, and are talking about stuff that you know superficially (or know nothing about) here. I'm not wasting another minute on you.
It is a crappy thing, but it's life -^ Carlo Pallini
-
harold aptroot wrote:
At least he will be better off knowing that they exist.
Fine, he'll know that such a thing exists. That's the only point I can take. But, I won't take the "it's closer to the goal" codswallop.
harold aptroot wrote:
And yes I gave you a 3, not because you disagree but because You are the one who is partically wrong. It would be closer to his goal.
Now, you're being ridiculous. How is it closer? He's trying to achieve something that would require an RTOS, but is doing that task on Windows. So, how is any approach going to be closer to the goal? Not only you don't know about the subject, but you're also down-voting because you think that I'm wrong. How long have you been doing C++ or programming Windows to say that using a multimedia timer can be closer to make Windows behave like an RTOS? I'd assume that you're a teenager, have never worked on any professional project, and are talking about stuff that you know superficially (or know nothing about) here. I'm not wasting another minute on you.
It is a crappy thing, but it's life -^ Carlo Pallini
Rajesh R Subramanian wrote:
I'm not wasting another minute on you.
Well thanks. But in my world any improvement means you're closer. And going from normal timers to multimedia timers is definitely an improvement if your goal is a very short wait. Thus it is closer. Are you getting extremely offensive over a definition of "closer"? Come on now.
Rajesh R Subramanian wrote:
He's trying to achieve something that would require an RTOS
Yes, so it's impossible, but so what? You can still get a lot closer to the goal than a 18ms resolution. Honestly now, an answer that is not right does not deserve a 5, a 4 is more fitting, you do have a point, however your definition of closer does not match the one in the dictionary. This isn't even a programming matter, it's just you having odd definition of being closer to a goal. Btw including my age in the argument is argumentum ad hominem - in other words, you would be wrong by default.
-
I need my program sleep 1 microsecond, but Sleep() can not do this. So, can I use select() instead Sleep() to do this?
timeout.tv_sec=0; timeout.tv_usec=1; FD_ZERO(&readfd); ret=select(0,&readfd,NULL,NULL,&timeout);
It's have any problem or not?Thanks all. It's looked like I need transplant my project From Windows to Linux or Unix. timeval's member tv_usec is a value in microseconds. It declaration and used in UNIX first. So, I think UNIX, FreeBSD for example can do this as possible.