[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Is there an easier way to cancel threads???
- From: Doug Rogers <rogers@...>
- Date: Fri, 28 Apr 2006 15:28:56 -0400
Diego Nehab wrote:
>> [Now you know why I'm so fond about non-pre-emptive approaches.]
> Dude, it's not like LuaThread is my favourite child. :) I
> don't know why people like threads...
I have come to the conclusion that preemptive threading was created not
to support blocking calls but instead to support computer science
master's degrees!
> We can use a condition variable and a counter to make sure
> we only exit lua_close when all threads are done. Is this a
> good solution? I think it is ok.
That's what I did in my own threading library. My 'tasks' use post() and
read() in a way similar to resume() and yield(). Each task has a pthread
condition variable + mutex in the C backend. When it dies it signals the
main counting semaphore for the tasking library. I never linked it in
with lua_close(), though. That would have been smart. I'm not terribly
satisfied with my approach, but it worked for a few fun cases.
The next time I think I need preemptive threading in Lua I will use
someone else's better design.
Doug
--
--__-__-____------_--_-_-_-___-___-____-_--_-___--____
Doug Rogers - ICI - V:703.893.2007x220 www.innocon.com
-_-_--_------____-_-_-___-_--___-_-___-_-_---_--_-__-_