[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: occasional threading in lua
- From: "Russ Cox" <rsc@...>
- Date: Mon, 27 Nov 2006 10:07:18 -0500
On 11/16/06, Russ Cox <rsc@swtch.com> wrote:
> This program ends up using just two pthreads.
is this true in the current implementation - both cases seem to create
a sequence of pthreads?
You're right -- there is a third pthread that gets created
and then almost immediately deleted every time a sleep happens.
This could be easily optimized away.
> I'd be happy to hear comments or suggestions for even
> simpler ways to accomplish this.
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.
on linux 2.6 x86, i noticed that the vmsize and rss keep increasing
(until vmsize maxes out at 3GB). since the pthreads are created as
"joinable" by default, their memory isn't reclaimed when they exit.
i added a global pthread_attr_t object, initialize it in luaopen_thread()
pthread_attr_init(&attr);
if(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) != 0)
luaG_runerror(L, "setdetachstate");
Aha, thanks!
and passed it as the second argument to pthread_create() in
luaT_vm_unlock(). another option would be to call
pthread_detach(pthread_self()) in luaT_scheduler().
i also noticed that the default stack size for each pthread is a
whopping 8MB (RLIMIT_STACK) on my linux box. depending on how many
concurrent threads one expects, is it worth having an option to reduce
this by using pthread_attr_setstacksize()?
It probably is worthwhile, though the only real issue here is
address space, not actual memory, since the memory will be
paged in on demand.
Russ