Perl의 thread model

각종 언어들의 Thread Model이 잘 설명된 글:A Threading Model Overview 에서 발췌

Perl

Perl has an interesting threading model, one which Mozilla borrowed for SpiderMonkey if I'm not mistaken. Instead of having a global interpreter lock like Python, Perl makes all global state thread local and spawns off a new interpreter with each new thread. This allows for true native threading. There are two catches though.

First, you must explicitly make variables available to threads outside your own. This is the nature of everything being thread local. The values must then be kept up to date across threads.

The second catch is that every new thread is very expensive to create. The interpreter is not small, and duplicating it with every thread makes for a lot of overhead.

요약하면 Perl thread model은 독특한데( Python, Ruby의 thread 구현은 현재 다각적으로 개선이 이루어지고 있지만 현 상태로는 멀티프로세서 환경에서 잇점을 얻기가 힘들다고 함 ) Mozilla의 SpiderMonkey도 이 모델을 빌렸으며  Perl의 새로운 각 thread는 새로운 해석기를 생성하며 global state를 thread local화하기 때문에 실제 native threading을 쓸 수 있게 한다.

이런 구조에서 조심해야하는 것은 thread local화 때문에 공유할 변수들은 모든 thread에서 최신의 상태에 접근 가능하도록 명시적으로 지정(thread::shared 모듈)을 해줘야 하며 thread 생성 시 thread별로 크기가 작지 않은 해석기를 독립적으로 가지기 때문에 그에 따른 오버헤드와 비용이다.

추가 참고문서: http://perldoc.perl.org/perlthrtut.html

0 TrackBacks

Listed below are links to blogs that reference this entry: Perl의 thread model.

TrackBack URL for this entry: http://aero.sarang.net/cgi-bin/mt/mt-tb.cgi/90

Leave a comment

About this Entry

This page contains a single entry by aero published on September 10, 2008 1:07 PM.

Perlmania Study 발표자료 was the previous entry in this blog.

Multiple e modifier is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Creative Commons License
This weblog is licensed under a Creative Commons License.
Powered by Movable Type 4.21-en