meaning of wait(NULL)
meaning of wait(NULL)
Can somebody tell me what is the meaning of
Wait(NULL) command.
I am aware of what wait command does, but I dont know what happens when parameter passed is (NULL).
Thanks
Wait(NULL) command.
I am aware of what wait command does, but I dont know what happens when parameter passed is (NULL).
Thanks
Re: meaning of wait(NULL)
Hmm, I'm not sure. I'm new to the whole OS dev'ing, but it seems like that parameter should be a number, like clock ticks or milliseconds... but the NULL makes no sense in that regard. So, I would say that in case it's probably calling Wait to use some default behavior, possibly to be run in highest priority.
- carbonBased
- Member
- Posts: 382
- Joined: Sat Nov 20, 2004 12:00 am
- Location: Wellesley, Ontario, Canada
- Contact:
Re: meaning of wait(NULL)
Why don't you look into the implementation of this wait() function and see what it does when the parameter == 0?
--Jeff
--Jeff
Re: meaning of wait(NULL)
CarbonBased: 0 != NULL
Re: meaning of wait(NULL)
At least in C++ the two are exactly the same: Stroustrup's FAQ
My guess is btw that wait(0) just means that the tasks wants to sleep until a new message arrives..
regards,
gaf
My guess is btw that wait(0) just means that the tasks wants to sleep until a new message arrives..
regards,
gaf
- carbonBased
- Member
- Posts: 382
- Joined: Sat Nov 20, 2004 12:00 am
- Location: Wellesley, Ontario, Canada
- Contact:
Re: meaning of wait(NULL)
Yes it does. Even if it didn't, casting it to an integer would surely yeild 0.bubach wrote:CarbonBased: 0 != NULL
Who's implementation of wait() are you using, anyway? Sounds like something from a compilers libc collection which is, probably, not overly useful in an OSDev environment (you'd have to rewrite it for your OS).
--Jeff
Re: meaning of wait(NULL)
Well sometimes it means "Skip the rest of the time slice".
On the other hand, sometimes it might mean infinite.
On the other hand, sometimes it might mean infinite.
*post*
Re: meaning of wait(NULL)
bubach, according to c and c++ standard NULL should be defined simply as 0 when defined correctly. There are several reasons why.
Firstly, while an "invalid" pointer may be any value in reality, it is considered to be up to the compiler to convert 0 use assigned/treated as a pointer to that value at compile time, but in the source it must still be 0.
Secondly, I have seen many implementations which use (void *)0 which is _incorrect_, here's why. The C standard says say you may not cast between a function pointer and a non-function pointer type. Well, void * is not a valid function pointer type! So if NULL were defined as (void *)0 then technically it would be illegal to assign NULL to a function pointer (and surely it should be).
all in all, even the creator of c++ says "just use 0".
proxy
Firstly, while an "invalid" pointer may be any value in reality, it is considered to be up to the compiler to convert 0 use assigned/treated as a pointer to that value at compile time, but in the source it must still be 0.
Secondly, I have seen many implementations which use (void *)0 which is _incorrect_, here's why. The C standard says say you may not cast between a function pointer and a non-function pointer type. Well, void * is not a valid function pointer type! So if NULL were defined as (void *)0 then technically it would be illegal to assign NULL to a function pointer (and surely it should be).
all in all, even the creator of c++ says "just use 0".
proxy
Re: meaning of wait(NULL)
I guess i was a bit tired when i wrote that. I was thinking more like: the char 0 != NULL or sth.. :S
Re: meaning of wait(NULL)
so many answers, but to the wrong question. i think the question is about the semantics of wait (0). in most operating systems thus a process/thread can relinquish its time slice to the os. and thus be (very) nice to other processes because they get rescheduled earlier.