Minutes of Meeting OCT 19 2006

November 26th, 2006 by SimonAW

Attendees

  • Bruce
  • Eliot
  • Steven
  • Rob
  • Chris
  • et al

Chris Introduction to Threads in Perl

Models

  • Boss/Worker
  • Work Crew
  • Pipeline

What kind of threads are Perl Threads

Perl Threads are specific to Perl. There are similarities between perl’s
threading system and others. Perl is not POSIX threads. There are
no mutexes or thread priorities and data is not shared between threads by default.

Creating Threads

Threads can be created via the threads module. When compiling perl from source it is important to tell Configure that you wish to use threads. The threading module is known as threads.


1 #!/usr/bin/perl
2 use threads
3 my $thr = threads->new(\&sub1);
4 sub sub1 { print "In thread\n"; 1;}
5 $thr->join;

Line 2
We create a thread and sub1 is executed as the thread.
Line 5
The parent thread waits for the child to return. Join will wait for a thread to complete and will retrieve the thread’s return value; In line 4 we returned ‘1′. join() will wait for that routine to finish and receive the return value;

Threads and data

The biggest difference between Perl’s threads and other threading
systems is that by default no data is shared. When a thread is created
there is a similar feel to what happens during a fork(). All data is
copied to the thread. In reality this is quite expensive in terms of
memory and cpu usage. To make threads useful one should share some
data. The module threads::shared is used to allow threads to share
data.

Some examples of sharing data:


1. #!/usr/bin/perl
2. use threads;
3. use threads::shared
4. my $foo : shared = 1;
5. my $bar = 1;
6. threads->new(sub { $foo++; $bar++})->join();
7. print "\$foo = $foo\n";
8. print "\$bar = $bar\n";

Line 4
We create a variable and mark is as shared. We then initialize
that variable to 1. Anything in a program you can share a variable.
poker tour giocogiochi online poker gratis7 card stud inlineaaces texas holdem multiplayerholdem poker online,poker texas holdem online,poker texas holdem on linesexy poker gratispoker tournament 2007scommesse internetnoble pokerpoker online italiapoker milanovideo poker gratispoker italiadownload video poker gratispoker pctexas holdem poker onlinetornei poker gratistornei texas holdembonus senza deposito pokerplay omaha poker freeregole omaharegole poker omahapoker holdem gratissuper pokeristruzioni gioco pokerplay 7 card stud onlinestrip poker gamescaricare gratis pokerhollywood pokerholdem poker,poker holdem gratis,holdem poker italiastreap poker on lineonline poker tournamentscarica gioco pokeronline poker roomtrucchi casino onlinecasino games proslots machines gratisgiochi casino onlineroulette russafree kenovideo poker online gratisbonus dei casinocasino italia bonusbetandwin casinoprobabilit? roulettegiochi casino online gratiscasino sanremo onlinegioco baccarat in lineavirtual casinoamerican roulette It is important to know that when you mark it as shared any values
in that variable are destroyed.
Line 5
We create a bar variable and do not share it.
Line 6
We create a thread and wait for it to finish. The thread simply
increments our two variables.
Line 7
Since we shared foo and the thread incremented it the value is
2.
Line 8
Even though the thread incremented bar we did not share it.
Value is 1.

Types of values that can be shared

Array’s, Hashes, and values can be shared. For an array and hash the
children are shared. There is an exception for the hash that only one
level deep will be shared. If you have a hash that has multiple levels you’ll
need to share each level of that hash. Only simple values or references to shared
data is allowed.


--- listing 4.2 ---
1.#!/usr/bin/perl
2.use threads;
3.use threads::shared
4.my %hash : shared = ();
5.$hash{level1} = &share({})

Line 5. We want hash named “level1″ to be shared between threads to we
mark it as shared.
Line 6. We assign the first value in the “level1″ hash. Note that we marked
it as shared before we assigned a value.

Locking

It is important that when multiple threads access the same data that the data is
protected. Perl can place a lock on a variable and a thread will block until
that lock has been released. There is no unlock method. The lock stays in effect until
it is out of scope. If a thread tries to lock the same variable within the scope of a
previous lock then it will be ignored.

--- Listing 5.1 ---
1. #!/usr/bin/perl
2. use threads;
3. use threads::shared;
4. my $LCK : shared;
5. my $foo : shared = 1;
6. my $thr = thread->new(sub {
7. lock($LCK);
8. $foo++; 1;});
9. { lock($LCK); print "\$foo = $foo\n"; }
10. $thr->join()

Line 4
We create a shared variable to use as locking. You can lock any variable
but to keep things clear I usually create one variable just to use for locking.
Line 5
We create a shared variable that we’ll protect using the lock
Line 6
New thread created
Line 7
Lock the variable. Note that the thread will block on this line until
the lock is avaialble.
Line 8
Simply increment $foo by one and return
Line 9
We lock our variable and print $foo. Brackets are used to illustrate the
concept of the lock being actinve within the scope of the lock. Once we
are out of scope variable is automatically unlocked.

Meeting NOV 16 2006 — Live –

November 16th, 2006 by SimonAW

My first “live” entry at my last Perl Mongers Meetup.

We are just talking about:


print map { $_->[0] }
sort { $a->[1] cmp $b->[1] }
map { [ $_, /(\S+)$/ ] } <> ;

We want to sort this by Lastname.
Data:


asd:Firstname Lastname

The magic diamond takes entire lines from stdinput. Sample Data is shown right above.

The last map creates an anonymous array with the original line and the last name. It is compared in the sort anonymous code block and printed out in the first map code block.

Atlanta.pm irc channel

November 16th, 2006 by mdw

Come join us at irc.freenode.net channel #atlanta-pm

I’ll try to camp out there as much as possible, and Simon will drop by to visit us after he heads back to Germany.

Minutes of Meeting SEP 21 2006

September 22nd, 2006 by SimonAW

Attendees

  • Chris
  • Stephen
  • Mike
  • Russ
  • Ryan
  • Rob
  • Bruce
  • Elliot
  • Simon

Ryan
Has some job oportunities (see mail attachment on the pm mailing list)

Stephen
Growl Notification Protocol
OpenSource Project UPD based
signs packet with password
shared secret approach
meant to run on a LAN

Intermission
Difference my / our
CPAN Problems/Issues with Module::Build (install manually will bring remedy - do not install with CPAN itself)

Bruce
Deobfuscation of cog’s mail address

Trivia (Cheesecake Factory)
We just got served. Voltron, represent!
Bugs Bunny vs Elmer Fudd Rap Battle
Dictionary definition of the word “kojak”
Red vs Blue

Minutes of Meeting AUG 17 2006

August 20th, 2006 by SimonAW

Attendees:

  • Bruce
  • Chris
  • Mike
  • Rob O.
  • Russ
  • Simon
  • Stephen

Bruce

Talk about refactoring a third party sort routine in Perl. When we are talking about refactoring this does not only mean to increase legibility of already present code but also increasing the program’s performance.

The final benchmark of the refactored sort routine showed significant improvement in time consumption.

[Source of the Perl Scripts and benchmark results to be added]

Trivia

In this meeting the following question came up: What has TexMate Vim hasn’t? After a while the answer was: You can’t switch tabs with one key press.

This is correct. Partly. You can switch (or cycle) the open tabs in Vim by pressing the key combination Ctrl+PgUP for the previous and Ctrl+PgDn for the next tab. So this takes two (in words: two) keys to be pressed. But we want one key press.

You can accomplish this by adding the lines
map <F9> :tabp<CR>
map <F11> :tabn<CR>

to your Vim startup file.

Now the the previous tab is selected by pressing F9 and the next tab is selected by pressing F11 since F10 is reserved for accessing the menubar.

First draft of a flyer to post for our meetings

August 6th, 2006 by Russ Thomas

APMers,

In reading through some of the archives for the mailing list, I came across a flyer that someone created in 2005 for the last group of meetings.

I took the liberty to edit that file and try a little different format. I’d like your comments/suggestions.

Atlanta PM August Meeting invite flyer (MS Word Format)

August 2006 Meeting Announcement in pdf format

Russ
——-
russthomas@mindspring.com

Minutes of Meeting JUL 20 2006

July 31st, 2006 by SimonAW

Attendees:

  • Russ
  • Stephen
  • Mike (2)
  • Bruce
  • Ryan (Host)
  • Simon

Bruce

  • PPI
  • Vanilla / Strawberry PERL
  • PERL Build Tools: MakeMaker must die!, Apache Ant for Java projects only (very powerful but a memory hog like any Java application
  • How to decode files (example: Pokemon Savegames) How to find out what type of file you have: the UNIX file command using Magic.
  • Organizational: Set up a blog at atlanta.pm.org. If a blog cannot hold the myriad of information expand to wiki.

Stephen

  • The Meetup.com Account is to be cancelled!

Any artistic folks ready to create a logo for the blog?

July 21st, 2006 by mdw

The blog looks great. Thanks to you for setting this up and your company for hosting.

So, any creative folks up to creating a perlish logo to put up top?  Would be a nice personal touch IMHO. My artistic talents rank just beneath my web design skillz, so I’ll challenge folks to submit some entries. The winner gets free drinks on me during the social portion of the next meeting they attend ( you must proide your own designated driver though!).

 

Russ T.