Re: [Sablevm-developer] java.lang.Thread.yield()
Brought to you by:
egagnon
From: Chris P. <chr...@ma...> - 2003-02-20 02:35:44
|
Hi Etienne, Prof. Etienne M. Gagnon wrote: >On Wed, Feb 19, 2003 at 08:36:58PM -0500, Chris Pickett wrote: > > >>I don't know what JNI_OK is defined to be (I couldn't find it with >>grep), but if it's zero then that's: >> >>if (sched_yield() != JNI_OK) >> _svmf_error_InternalError (env); >> >> > >No!!!! JNI_OK is used by _svmf_* functions to indicate success. You >should never make any relation between the actual integer value JNI_OK >is defined as, and the accidental value it matches in another context! > > >If I decided to change JNI_OK to be defined as 36, the code above >would start misbehaving (assuming JNI_OK was originally defined as >zero). > Okay. Where is JNI_OK defined? > >Also, you should *ALWAYS* check return values of non-void functions. >I had not double-checked if sched_yield returned a value. I guess I >should never trust submitted code and review thoroughly every line of >code and the documentation of every called library function... > > Well, actually, I realized last night about checking the error status, after I emailed you to say that I would send a patch today, but then today you had already committed the code. Then I got caught up in making scripts, and didn't get around to telling you yet. sched_yield() returns 0 if there was no problem, or -1 if there was an error. sched_yield() is not necessarily posix compliant, so perhaps you'd better use pthread_yield() ... pthread_yield() doesn't return a value ever either, so just replace sched_yield() with pthread_yield() and forget about the error check. sched_yield() is in sched.h which is in the GNU C library, whereas pthread_yield() is in pthreads. The only reason I used sched_yield() was because that's what you and Clark and I talked about. Sorry for not letting you know earlier and not checking the code I sent you. Transgression #1. Chris |