meaning of wait(NULL)

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
as_Sap
Posts: 1
Joined: Mon Nov 14, 2005 12:00 am

meaning of wait(NULL)

Post 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
Shark8
Member
Member
Posts: 27
Joined: Wed Nov 02, 2005 12:00 am

Re: meaning of wait(NULL)

Post 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.
User avatar
carbonBased
Member
Member
Posts: 382
Joined: Sat Nov 20, 2004 12:00 am
Location: Wellesley, Ontario, Canada
Contact:

Re: meaning of wait(NULL)

Post by carbonBased »

Why don't you look into the implementation of this wait() function and see what it does when the parameter == 0?

--Jeff
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re: meaning of wait(NULL)

Post by bubach »

CarbonBased: 0 != NULL
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
gaf
Member
Member
Posts: 349
Joined: Thu Oct 21, 2004 11:00 pm
Location: Munich, Germany

Re: meaning of wait(NULL)

Post 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
User avatar
carbonBased
Member
Member
Posts: 382
Joined: Sat Nov 20, 2004 12:00 am
Location: Wellesley, Ontario, Canada
Contact:

Re: meaning of wait(NULL)

Post 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
Legend
Member
Member
Posts: 195
Joined: Tue Nov 02, 2004 12:00 am
Contact:

Re: meaning of wait(NULL)

Post by Legend »

Well sometimes it means "Skip the rest of the time slice".
On the other hand, sometimes it might mean infinite. ;)
*post*
User avatar
proxy
Member
Member
Posts: 108
Joined: Wed Jan 19, 2005 12:00 am
Contact:

Re: meaning of wait(NULL)

Post 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
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re: meaning of wait(NULL)

Post 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
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
boot_rom
Posts: 4
Joined: Tue Nov 22, 2005 12:00 am

Re: meaning of wait(NULL)

Post 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.
Post Reply