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

打開APP
userphoto
未登錄

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

開通VIP
epoll_wait是線程退出點(diǎn)嗎? - General - 豆花魚片加工室
epoll_wait是線程退出點(diǎn)嗎?
在Linux上,epoll_wait是否cancellation point,取決于glibc的版本.
好像在glibc-2.4以上版本中才支持.

假如系統(tǒng)epoll_wait不是cancellation point,那么在某線程執(zhí)行epoll_wait時(shí),另一線程通過(guò)pthread_cancel發(fā)出cancel信號(hào),那么表現(xiàn)為:
1. 在epoll_wait返回之前,線程阻塞該信號(hào),并不響應(yīng);
2. 當(dāng)epoll_wait返回時(shí),線程立即退出(所有資源不會(huì)被釋放),在此之前即使通過(guò)pthread_cleanup_push注冊(cè)了銷毀時(shí)的回調(diào)函數(shù)也不會(huì)被執(zhí)行;同時(shí),如果有線程阻塞在pthread_join等待此線程退出的話,則會(huì)返回.


測(cè)試代碼如下:

/*
  test epoll_wait is a cancellation point.
  glibc-2.4 or later support.

  fedora 5 support.
*/


#include <sys/epoll.h>
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>

void * run (int * events) {
    struct epoll_event storage;

    printf("Wait start.\n");
    /* block forever */
    epoll_wait(*events, &storage, 1, -1/*10000*/);

    printf("Wait stop.\n");

    return NULL;
}

int main (void) {
    int events;
    pthread_t new_thread;

    events = epoll_create(1);
    pthread_create(&new_thread, NULL, (void * (*) (void *))run, &events);
    
    /* wait for enter keypress to try pthread cancellation */
    getchar();
    printf("Cleanup start.\n");
    pthread_cancel(new_thread);

    /* let's see if this returns or not */
    pthread_join(new_thread, NULL);
    
    /* if to here, the epoll_wait is a cancellation point. */
    printf("Cleanup stop.\n");
    
    
    close(events);
    return 0;
}

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
【討論】malloc的可重入性和線程安全性
C++多線程入門(一)
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服