Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^6: How can I force thread switching?

by ajl52 (Novice)
on Sep 30, 2013 at 12:36 UTC ( #1056346=note: print w/ replies, xml ) Need Help??


in reply to Re^5: How can I force thread switching?
in thread How can I force thread switching?

Thanks for the eval { ... } suggestion, I'll experiment.

The reason why I use my own thread ids is I want to be 100% sure they lie in 1..number_of_threads range (0 is used for scrolling messages).

What is my concern?

Once again, I did not give the full picture.

As soon as I start multi-thread operation, the screen is split into an upper scrolling region and a lower non-scrolling status area where each line "belongs" to a thread.(*)

Thus, I have the traditional scrolling information area for routine messages and a steady area where "accidents" can be shown for a longer period of time. Of course, a reminder summary is printed when everything is done.

Now, since my thread id is used to index the private line, this id MUST stay in the desired range.

Your Q implementation is exactly what I need. Since i'm not the only one to need this feature, I wonder why this is not included in the queue package. All your arguments make great sense. My concern is speed (I already mentioned that the whole process improved from 2:30 hours to 57 minutes) and I'd like to squeeze all inefficiencies out of my code, but there are very clumsy implementations in other sections (notably when it comes to parsing text).

(*) This heavily uses ANSI escape codes. I made the assumption current terminal emulations implement the most usual sequences (according to Wikipedia) and avoided "cute" sequences tied to a specific implementation. I allowed back/foreground colours and cursor addressing.


Comment on Re^6: How can I force thread switching?
Download Code
Re^7: How can I force thread switching?
by BrowserUk (Pope) on Sep 30, 2013 at 13:29 UTC
    The reason why I use my own thread ids is I want to be 100% sure they lie in 1..number_of_threads range (0 is used for scrolling messages).

    Understood, but since you are only using 4 threads, and tids are monotonically increasing; there is no problem. But, your call.

    Your Q implementation is exactly what I need. Since i'm not the only one to need this feature, I wonder why this is not included in the queue package.

    I wrote it for my purposes. In part to add the self-limiting aspect, in part to discard what I consider to be broken functionality that was added to Thread::Queue (all the peek & random access nonsense has no place in a queue implementation).

    I posted it here because someone else had the same need. I've never got around to publishing it because the aggravation of doing so is more than I need.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1056346]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2014-07-11 09:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (222 votes), past polls