Page 1 of 1
meaning of wait(NULL)
Posted: Mon Nov 14, 2005 12:00 am
by as_Sap
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
Re: meaning of wait(NULL)
Posted: Mon Nov 14, 2005 12:00 am
by Shark8
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.
Re: meaning of wait(NULL)
Posted: Mon Nov 14, 2005 12:00 am
by carbonBased
Why don't you look into the implementation of this wait() function and see what it does when the parameter == 0?
--Jeff
Re: meaning of wait(NULL)
Posted: Wed Nov 16, 2005 12:00 am
by bubach
CarbonBased: 0 != NULL
Re: meaning of wait(NULL)
Posted: Wed Nov 16, 2005 12:00 am
by gaf
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
Re: meaning of wait(NULL)
Posted: Wed Nov 16, 2005 12:00 am
by carbonBased
bubach wrote:CarbonBased: 0 != NULL
Yes it does. Even if it didn't, casting it to an integer would surely yeild 0.
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)
Posted: Thu Nov 17, 2005 12:00 am
by Legend
Well sometimes it means "Skip the rest of the time slice".
On the other hand, sometimes it might mean infinite.
Re: meaning of wait(NULL)
Posted: Thu Nov 17, 2005 12:00 am
by proxy
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
Re: meaning of wait(NULL)
Posted: Fri Nov 18, 2005 12:00 am
by bubach
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)
Posted: Tue Nov 22, 2005 12:00 am
by boot_rom
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.