about thread-safe and reentrant function

42 views
Skip to first unread message

sung descent

unread,
Mar 2, 2013, 9:09:22 AM3/2/13
to julu...@googlegroups.com
Dear all,

  1. http://tw.myblog.yahoo.com/blue-comic/article?mid=253&amp%3Bprev=257&amp%3Bl=f&amp%3Bfid=26
  2. http://qt-project.org/doc/qt-4.8/threads-reentrancy.html

看了這兩篇有個疑問:
ref 1 提到  thread-safe and reentrant function 沒有一定的關係, 一個 function 可以符合  thread-safe and reentrant function 或都不符合, 或只符合其中之一

ref 2 卻說 a thread-safe function is always reentrant

大家的看法呢?為了簡化討論, 只討論 c function, 不討論 c++ class。

Ben6

unread,
Mar 3, 2013, 11:49:28 PM3/3/13
to julu...@googlegroups.com
有一種case的function 本身是 thread-safe,但卻不是Process-safe。如存取同一個檔案或資源的情況。(我不確定這種case 算不算 reentrant。)

sung descent

unread,
Mar 3, 2013, 11:56:09 PM3/3/13
to julu...@googlegroups.com
另外一個疑惑:
http://www.unix.org/whitepapers/reentrant.html
reentrant 就是用來對付 multi-thread 的, 為什麼又會來一個 thread-safe 的名詞。上述文章都只提到 reentrant。


2013/3/4 Ben6 <ben...@gmail.com>
有一種case的function 本身是 thread-safe,但卻不是Process-safe。如存取同一個檔案或資源的情況。(我不確定這種case 算不算 reentrant。)

--
您已訂閱「Google 網上論壇」的「juluOSDev-星系統社群」群組,因此我們特別傳送這封郵件通知您。
如要取消訂閱這個群組並停止接收來自這個群組的郵件,請傳送電子郵件到 juluosdev+...@googlegroups.com
請前往以下網址造訪這個群組:http://groups.google.com/group/juluosdev?hl=zh-TW。
如需更多選項,請前往:https://groups.google.com/groups/opt_out。
 
 

Mars Cheng

unread,
Mar 4, 2013, 4:20:52 AM3/4/13
to julu...@googlegroups.com
就我的了解, reentrant 表示當某個 procedure 執行到一半被中斷,可以再被成功呼叫並獲得正確結果,就是 reentrant。reentrant是thread的觀念還沒有時,針對中斷就有的概念。thread-safe procedure 則不一定能達到reentrant,以 wikipedia 的例子(thread-safe, but not reentrant, would hanged if call it again when interrupted in body):

int function()
{
 mutex_lock();
 ...
 function body
 ...
 mutex_unlock();
}
Message has been deleted

sung descent

unread,
Mar 16, 2013, 12:29:40 PM3/16/13
to julu...@googlegroups.com
在 pthread 多緒程式設計 p237 提到 threadsafe and reentrant function:

簡單提一下 (詳細請參閱該書籍):
reentrant function: 不可使用 static, global data
thread safe: 使用 mutex 來保護 global data

這應該就比較容易理解了。
Reply all
Reply to author
Forward
0 new messages