in reply to Missing (i)threads Features?
A few thoughts so far
Nice appears to have a range of possible value +20 to -20, with positive values lowerig priority and negative raising it. This is true for processes. How are threads implemented under *nix? Can their priorities be manipulated independently of their process?
Win32 uses a range of 0 to +31, but this is abstracted into a number of classes IDLE, BELOW_NORMAL, NORMAL, ABOVE_NORMAL, HIGH and REALTIME. (Not all are available on all platforms). There is also a scheme for dynamically boosting a threads priority for short periods.
I've no idea what equivalents are available under VMS/MAC etc.
For the most part, most OSs are probably best left to manage such matters for themselves, but I can see the desirability of designating a thread to run only when nothing else needs the cpu and also for marking a thread to run immediately when an asynchronous event unblocks.
I think that abstracting this into a set of 3 or 4 'levels' makes sense. It would take some expertise on each of the different OSs to translate the levels into appropriate numerical values for each platform.
Rather than havong a facility to detect whether yield actually yields, it would be better if yield where implemented to do something sensible--like sleep for short periods--on those platforms where the OS doesn't provide the facilty native. This is probably a simplistic view, but the ought to be some approximation possible on most platforms?
It can be useful to be able to create threads and suspend them pending some event. Without knowledge of how threads are implemented on other platforms I can't say much more on this.
The situation is the 'pool of threads' scenario where you want to have the main thread block until one of the current threads has finished. Effectively, I find myself wanting to code
if( @threads > LIMIT ) { threads->join_any(); } else { push @threads = threads->new( \&childStuff, @args ); }
This is the threaded equivalent of wait (as opposed to waitpid) in the forking world.
A minor critique of your current implementation of Thread::Running etc. is that I have to supply a list of threads to be checked. The 'system' already knows what threads there are, and it shouldn't be necessary for me to supply a list to running(), tojoin(), exited(). It becomes a pain to remember to remove threads that you have joined from the list before passing it back in. It requires me to duplicate the hash that you are using internally.
One of the biggest advantages of multi-threading over multi-processing, is that (with appropriate debugger support) it is 'easier' (for some meaning of that term) to debug if all the threads of execution are in a single process and managable from a single dubugger session.
It should be possible to single step, set breaks and watches, view source around the current point on a thread by thread basis. The debugger prompt should indicate which thread is executing each line when tracing etc.
This is one place where the ability to suspend/resume threads can be useful.
Most of this stuff would be better, more easily and more efficiently done in threads.xs rather than requiring several extra modules each with its own state which (often) duplicates state already existing at the system level. Perhaps the powers that be would accept a threads::util module for this sort of stuff.
I'm accutely aware that I am (legitimately) open to the critisism "Okay. Where are the patches?". The only response can give is "I'm working on it", but it going slowly:(
To date, I still haven't succeeded in building perl with a free compiler such that it isn't emasculated (no large file support or PerlIO for example).
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Missing (i)threads Features?
by liz (Monsignor) on Aug 20, 2003 at 17:03 UTC | |
by BrowserUk (Patriarch) on Aug 21, 2003 at 20:12 UTC | |
by liz (Monsignor) on Aug 22, 2003 at 16:06 UTC | |
by BrowserUk (Patriarch) on Aug 22, 2003 at 18:57 UTC |