수요일, 2월 02, 2005

threading

to be threaded or not?

어려운 물음이지만 threading 은 일반적으로 다음과 같은 장점을 제공한다.

1. lightweight context switching
여러 리소스를 공유하기 때문에, (특히 page table entry ) thread to thread 로 context switching 하는 것은 process to process 보다 가벼울 수 밖에 없다. CS 가 잦을수록 process model 에 비해 load 가 낮은것을 확인할 수 있다.

2. easiness of programming
memory 와 file descriptor를 share 하는 것은 여러모로 프로그래밍하기 편리하다.

3. user level mutex
기본적으로 memory variable 을 atomic 하게 억세스(고전적인 test&set 종류의 instruction) 하는것으로 mutual exclusion 을 구현할 수 있다. 그런 이유로 기본적인 mutex primitive 인 POSIX 의 pthread_mutex_lock() 이나 Win32 의 EnterCriticalSection()등 thread 에서 사용할 수 있는 mutex 들은 user level mutex 이다.
kernel level mutex 를 사용한다면, syscall overhead 와 kernel overhead 가 든다. process 에서 사용할 수 있는 mutex primitive 들은 kernel level mutex 이다. 물론 shared memory 를 사용해 process 끼리 user level mutex 를 구현할 수도 있지만...

단점은?

Heap Contention 이다. 보통 malloc 의 경우 thread safety 를 보장하지만 별로 좋은 퍼포먼스를 제공하지 않는다. 그런 이유로 heap contention 이 일어날만한 경우라면 보통 pre-allocation/pooling 으로 많이 해결하지만, 그 경우도 contention 은 충분히 문제가 될 수 있다. custom malloc 으로 heap contention 문제를 해결할 수도 있고, 다음은 그런 라이브러리중 하나다.

http://www.cs.umass.edu/~emery/hoard/

2 Comments:

At 3:36 오후, Anonymous 익명 said...

I'm newbie here, I hope to get friends at this forum

 
At 8:12 오후, Anonymous 익명 said...

블로그 관리자가 댓글을 삭제했습니다.

 

댓글 쓰기

<< Home