This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

pthreads and epolling question


Hi,

First of all, my apologies in advance if this is the wrong place for
such questions. As it stands, I'm merely trying to gather a bit more
information on this _possible_ problem. (And first time emailing the
libc list, to boot...)

The question is as follows: why is epoll_wait() not a pthread
cancellation point?
- The epoll_wait() call meets the definition of "syscall that may block".
- The behavior differs from poll() and friends.
Is this by design? And if so, what is the rationale?

Here is the test snippet used to check:
=======================================
#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);
    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);
    printf("Cleanup stop.\n");
    close(events);

    return 0;
}
=======================================
Compiled with: -lpthread -O3
=======================================

I'm sure it's a problem of mine somewhere (something I am overlooking or
flat out don't know), but it never hurts to make sure. :-)

Thanks in advance,
-Vadim Lobanov


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]