Re: [Sablevm-developer] java.lang.Thread.yield()
Brought to you by:
egagnon
From: Bruno D. <bru...@ma...> - 2003-02-20 03:10:31
|
Hi Chris, Etienne is right. You do not need to know where JNI_OK is defined. Unless you want to modify the value (and you don't want to that, of course), you should not care. But to satisfy your curiosity, look at src/libsablevm/include/jni.h. This is the standard place to define it, BTW. You should have been able to find that easily using grep. Cheers, Bruno On Thursday 20 February 2003 02:35 am, Chris Pickett wrote: > 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 |