国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
Linux?-?errno是不是線程安全的

    觀點(diǎn)一:

    errno是個(gè)全局變量,應(yīng)該不是線程安全的吧.

    觀點(diǎn)二

    可以的。
    extern int*__errno_location(void)
    #define errno (*__errno_location())
    保證自己維護(hù)一個(gè);

    觀點(diǎn)三:

    沒問題,線程之間不影響,實(shí)際errno是一個(gè)函數(shù);

    觀點(diǎn)四:

    線程對(duì)信號(hào)的反應(yīng),會(huì)隨系統(tǒng)不同而有些差異,并不是全部按照posix標(biāo)準(zhǔn)(記得早期的posix標(biāo)準(zhǔn)在這一點(diǎn)上似乎也比較模糊),在redhat linux7.2上,發(fā)送給進(jìn)程的信號(hào),會(huì)被發(fā)送給進(jìn)程內(nèi)所有的線程,而在solaris和redhat9上,只有主線程才接受到發(fā)給進(jìn)程的信號(hào)另外,要當(dāng)心在多線程應(yīng)用中error變量只有在定義了宏_REENTRANT后,才會(huì)有如下的定義出現(xiàn):
    int * __errno_location();
    #define errno (*__errno_location())
否則,errno只是一個(gè)非線程安全的全局變量,因此perror也將沒有準(zhǔn)確的含義。
 
    我自己在虛擬機(jī)上安裝的Fedora 5中用man errno得到如下內(nèi)容,請(qǐng)大家認(rèn)真閱讀:
    The <errno.h> header file defines the integer variable errno, which is set by system calls and some library functions in the event of an error to indicate  what  went wrong. Its value is significant only when the call returned an error (usually -1), and a function that does  succeed is allowed to change errno. Sometimes,  when  -1 is also a valid successful return value one has to zero errno before the call in order to detect possible errors.
    errno is defined by the ISO C standard to be  modifiable  lvalue of type int,  and  must not be explicitly declared; errno may be a macro. errno is thread-local; setting it in one thread does not affect its value in any other thread.
    Valid error numbers are all non-zero; errno is never set to zero by any library function.  All the error names specified by POSIX.1  must  have distinct  values,  with  the exception of EAGAIN and EWOULDBLOCK, which may be the same.
   
    至于什么是thread_local,下面給出一段Windows上TLS的定義供參考學(xué)習(xí):
       Thread local storage (TLS) is the method by which each thread in a multithreaded process allocates a location in which to store thread-specific data.
       我的理解就是每個(gè)線程都有一個(gè)自己的errno,互相之間不影響。其實(shí)等于沒有說,setting it in one thread does not affect its value in any other thread 已經(jīng)說的夠清楚了。呵呵!
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
POSIX semaphore: sem_open, sem_close, sem_post, sem_wait
Linux多線程pthread
淺析 Linux 中的時(shí)間編程和實(shí)現(xiàn)原理,第 1 部分: Linux 應(yīng)用層的時(shí)間編程
linux線程semaphore使用--mutex與binary semaphore的區(qū)別
Linux open函數(shù)簡(jiǎn)介
第三篇:errno.h快速入門
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服