pthread에서 현재 다른 쓰레드로의 context전환을 막는 방법은?

jj의 이미지

안녕하세요?

간단한 RTOS용 프로그램을 linux로 포팅하고 있습니다. 해당 OS는 vxworks였습니다.

RTOS의 task들을 linux에서 thread로 맵핑하고 있습니다. pthread 인터페이스를 사용하고 있구요.

vxworks의 task들이 전역변수를 공유해서, 자연스럽게 thread로 맵핑이 되지요.

그런데 vxworks에 있는 taskLock 기능을 thread로 처리하려고 하니 문제가 생겼습니다.

taskLock은 task간의 context switch을 금지시킨다는 얘기입니다. taskLock 을 호출하고, taskUnlock하기 전에는 아무리 높은 task가 치고 들어오려 해도, context전환이 이러나지 않습니다.

thread에서도 이런게 가능한가요? 예를 들어, 한 프로세스가 3개의 thread로 구성된 경우에, 특정 thread에서 , 원하는 구간 동안 (taskLock호출 시점부터 taskUnlock시점까지) 다른 쓰레드가 실행되는걸 막는게... (다른 쓰레드들 스스로 멈추는게 아니라, critical section을 가진 코드가, 다른 쓰레드들을 강제로 멈추게), 사실은 context 전환이 일어나지만, 더이상 코드가 진행되지 않으면(?) 됩니다.

언듯 드는 생각인, 전체 쓰레드에 대한 구조체를 유지하고, 모든 쓰레드가 특정 signal 핸들러를 가지며, taskLock을 호출하는 놈이, 다른 쓰레드들에 signal 을 쏘고, 해당 signal 핸들러는, 스스로를 특정 flag가 변할때까지(taskUnlock에서 세팅) 멈추게 하는 방법이 개념적으로 그려집니다만, 감이 잘 안오네요.

bushi의 이미지

pthread_mutex_lock()
pthread_mutex_unlock()

마스터 역할을 하는 놈이 있다면, 좀 더 응용해서...
슬레이브는 pthread_cond_wait() 으로 기다리고
마스터가 pthread_cond_signal() 로 풀어줄 수도 있습니다.

익명사용자의 이미지

jj의 이미지

제가 원한건 task안쪽에서 pthread API를 전혀 손대지 않는 방향으로 작업하는것이었죠. mutex를 쓰려면, 명시적으로 task에서 mutex를 건드려 줘야하고, 특정 부분에서 멈출 수 있는 반면, 제가 원한건 어떤 부분에서 실행하던지, 멈추는걸 원했습니다.

어렴풋이 signal로 하면 될것 같다였는데, 역시 joinc에 있네요.

http://www.joinc.co.kr/modules/moniwiki/wiki.php/article/%BE%B2%B7%B9%B5%E5%BF%CD_%BD%C3%B1%D7%B3%CE#AEN70
답변 주신분들 감사합니다...

--

콘쏠의힘

--
Life is short. damn short...

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.