[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: occasional threading in lua
- From: Mark Hamburg <mhamburg@...>
- Date: Sun, 14 Jan 2007 12:18:37 -0800
on 11/27/06 7:07 AM, Russ Cox at rsc@swtch.com wrote:
>> it seems like sched_mutex is acquired iff vm_mutex is held - could we
>> get by with just one mutex?
>
> Yes, indeed. Originally they did not overlap, but in their
> current form the sched_mutex can definitely be dropped.
Old thread, but I'm reading this again because we're looking at replacing
our multiple universe implementation with something more along these lines.
It would seem that the implementation posted in the original message is over
eager to create threads. Unlock will create a new thread whenever there
isn't a scheduler waiting to start. I would think that one would only want
to do this when there wasn't some code waiting on the VM mutex. Was that the
original reason for sched_mutex and why was it removed?
In other words, should the code have been as it is in the original message
except that luaT_vm_lock should be:
/*
* Grab exclusive use of the Lua VM.
*/
LUAI_FUNC void luaT_vm_lock (lua_State *L) {
pthread_mutex_lock(&sched_mutex);
++vm_waiting;
pthread_mutex_unlock(&sched_mutex);
pthread_mutex_lock(&vm_mutex);
}
With some more thought, one could probably create a version that used atomic
add and subtract to reduce the amount of mutex work.
Mark