( (
) )
( Twine -- An Unassuming Little Threading Library (
) -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- )
( ( ) ( ) ) ( ( ) ) (
) ) ( ) ( ( ) ) ( ( )
( ) ) ) ( ) (
) ( )
)
)
( Features
)
-- Easy userspace threads
-- Thread preemption after 10ms time slice
-- Mutexes
)
( Usage
)
-- Look at thread_test.c to see basic thread usage,
and mutex_test.c for mutex usage.
-- But basically:
twine_init(); // start the library
twine_create(foo, x); // create a thread
twine_yield(); // yield control to another thread
(
) Notes
(
-- Only compiles on Linux (or anything with the makecontext,
setcontext, etc. functions, which for some reason are
missing on OSX).
(
) Improvements
(
-- I'm probably not going to do any more work on this, but if I
were, here are some possible improvements that could be made -
or you could fork, implement them or others, and I'll pull it
back.
-- Currently the twine_create function only accepts functions that
return void and have one argument. I know of no way of getting
around the void return, but you can allow more arguments by
changing our call to makecontext in thread.c. See
/usr/includes/ucontext.h for details.
-- Figuring out a better slice time (10ms was pretty much picked
at random), or letting the user set it when he calls twine_init.
-- Priority scheduling - I had planned on having it, but I never got
around to it.