프로그래밍

스레드 안정성

Bestend 2011. 7. 19. 16:19
C++ 및 STL에서 손을 놓은지도 벌써 수년이 되어가건만, 백만년전쯤에 만들어놓은 STL 사이트 때문인지 가끔 STL 관련 문의를 메일로 받곤 하는데, 오늘 아침은 STL에서의 thread-safety에 관한 문의 메일을 받았다. STL로 thread programming을 해본 적이 없는 내가 답변할 자격이 있는건가.

Thread-safety는 'Standard C++ Library'에서 강제하는 사항이 아니니까, library implementation마다 구현 수준이 약간씩 다른데, 좀 더 general한 답변을 위해 관련 내용이 담긴 링크를 알려주었다.참고로, Visual C++은 Dinkumware의 것을 라이센싱하여 사용하고 있고, g++의 STL 라이브러리(libstdc++)는 SGI STL code를 기반으로 개발되었으며, SGI STL에 구현되어 있는 thread-safety의 요점은 다음과 같다. (from SGI STL Overview)

  • simultaneous read access to the same container from within separate threads is safe
  • simultaneous access to distinct containers (not shared between threads) is safe
  • user must provide synchronization for all accesses if any thread may modify shared container
PS: 그러고보니, 내가 1998년에 ODMG의 OQL query processor prototype을 구현할 때 STL을 사용했었으니까. 히익~ 그게 벌써 6년전이야?! 그냥 아무렇지 않게 '그 때'를 이야기하다가, 막상 이렇게 지나온 시간을 햇수로 꼽아보다 보면 흠칫 놀래곤 한다.