[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] Document keyUp




On Dec 25, 2004, at 2:30 PM, Jan Trützschler wrote:

as far as i can see this is called before the lock:

			PyrSymbol *method = getsym("keyUp");

			if (pobj) {
				pthread_mutex_lock (&gLangMutex);

yes, this is wrong. If another thread like a timer were to take the lock and define a new symbol, then the getsym could crash.
getsym must be done after the lock is taken.





compiledOK must be tested again inside the lock.

like this?

			PyrSymbol *method = getsym("keyUp");

			if (pobj) {
				pthread_mutex_lock (&gLangMutex);
				if(compiledOK){
					....

so is it neccessary to have check two times for  compiledOK ?


yes, because in the meantime the value may have changed unless you own the lock.