Multithread-safe 란 정확히 어떤 개념인가요?

gyxor의 이미지

검색결과..
http://www.ictp.trieste.it/~manuals/programming/sun/c-plusplus/tools_ug/mul_7946.htm
에서
Tools.h++ is multithread safe. In other words, all Tools.h++ functions behave the same in a multithreaded environment as in a single-threaded environment.
이런 부분이 나옵니다.
멀티쓰레드임에도 싱글쓰레드 환경인것 처럼.. delay없이 여러 쓰레드가 빠르게 동작한다는게
multithread-safe 인가요 ?
자세한 답변부탁드립니다.

segfault의 이미지

API에 따라서 멀티쓰레드 환경에서 쓸 수 없거나 쓰면 위험한 것이 가끔씩 있습니다.
(strtok가 그 예중 하나죠.)

저건 멀티쓰레드 환경에서도 안전하게 작동한다는 말인것 같군요.
______
mono* in the swirl

sangwoo의 이미지

Single-threaded process와는 달리, 여러개의 thread가 같은 주소공간을 공유하기 때문에, 함수의 구현에 static variable을 사용했다든가 하는 경우에, 그 변수의 값을 여러 thread에서 각각 변화시킬수 있는 등의 synchronization 의 문제가 생깁니다. 그것을 염두에 두고, side effect가 없도록 작성한 함수들을 thread-safe라고 합니다.
google에서 thread safe를 검색해보시면 많은 참고자료를 보실 수 있습니다. :-)

----
Let's shut up and code.

----
Let's shut up and code.

IDNed의 이미지

쓰레드 안정성은 동기화 많이 한것 때문이 아닙니다.

구글이를 검색하시면 되겠지만...
속도가 느린 것은 설계상의 오류일 뿐이지만 thread-safe 오류는 아예 의도되지 않았던 동작이 나와버립니다.

ex)

int a=0;
 
void thread1(){
 for(;;)
  printf("%d\n",++a);
}
void thread2(){
 for(;;)
  printf("%d\n",a);
}
sangwoo의 이미지

[snip]
IDNed님의 예는 변수 a, 또는 stdout을 동기화하지 않고 쓴 예로 볼 수 있습니다.
thread-safe한 코드를 원한다면, a의 값을 바꾸기 전에 mutex등으로 보호하도록 하면 되겠지요. 아니면 conditional variable을 사용하셔도 좋고.. 물론, incr_var() 이런 함수를 만들어서 사용하셔도 좋겠습니다.

지금 synchronization을 제외한 다른 thread-safeness에 대한 문제는 생각이 잘 나지 않는데요, 어떤 경우가 있을까요?

----
Let's shut up and code.

----
Let's shut up and code.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.