Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

A few thoughts so far

  1. Set/GetThreadPriority / Nice.

    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.

  2. Yield.

    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?

  3. Suspend/Resume.

    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.

  4. Thread::Running is nice, but one of the main uses I had for this is still non-trivial to code.

    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.

  5. Debugger support for threads needs improvement.

    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.

  6. die, warn and Carp should all include the thread id in their output by default in threaded applications.

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).

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
If I understand your problem, I can solve it! Of course, the same can be said for you.

In reply to Re: Missing (i)threads Features? by BrowserUk
in thread Missing (i)threads Features? by liz

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (4)
    As of 2018-03-25 00:26 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (299 votes). Check out past polls.