티스토리 툴바


Dev2009/03/15 20:20
reference:http://www.gamasutra.com/features/20060630/paquet_01.shtml

1. introduction
Interlocked Operation은 여러 쓰래드에 의해서 공유되는 변수들에 접근의 동기화를 위한 간단한 메커니즘을 제공한다.
interlocked Operation은 기존의 동기화 명령어를 대채하지는 못하지만 특수한 상황에서 그들을 보완할 수 있다.

2. What are interlocked operation?
interlocked operation들은 atomic 방법에서 integer-sized 와 pointer-sized 변수들의 빠른 업데이트 방법이다.
interlocked operation들은 o/s가반의 방법들 보다 하드웨어 기반의 동기화 방법들 처럼 높은 퍼스포먼를 가진다.
interlocked operation들은 내재 명령(instrinsic function)처럼 구현되며 어떤 경우에는 하나의 프로세서 명령으로 변경된다.

interlocked operation들은 atomic이다. 어떤 변수에 데이터를 쓰는 동안 다른 쓰래드에서 쓸수 없다. 읽는 것 또한 마찬가지이다.  게다가 interlocked operation의 atomiccity는 cpu들 사이의 오감을 보장한다.

3. The pros od interlocked operation
기존의 lock 메커니즘과 비교했을때, interlocked operation은 가변고 효과적이다. 이는 많은 장점을 가지고 이다.

interlocked operation은 mutex object나 critical section처럼 wait상태를 가지지 않는고 바로 실행한다. 이로서 lock-free, wait-free, non-blocking 프로그래밍이 가능하다.

interlocked operation을 이용해서 복잡한 동기화 primitive를 비교적 쉽게 만들수 있다. 아래 코드는 간단하게 interlocked operation을 이용하여 critical section API를 구현하였다.

#define CS long
#define CS_FREE 0
#define CS_USED 1

void InitializeCS(CS* pCS)

{
  // Set the free flag
  *pCS = CS_FREE;
}

void EnterCS(CS* pCS)
{
  while (_InterlockedCompareExchange(pCS, CS_USED, CS_FREE)
  == CS_USED)
  {
    // Spin until we see the free flag then acquire
    // the critical section by setting the used flag
  }
}

void LeaveCS(CS* pCS)
{
  // Set the free flag
  _InterlockedExchange(pCS, CS_FREE);
}


4.The cons of interlocked operaions
 명령어가 제한적이다...



크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by interjh