Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6966231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:09:55+00:00 2026-05-27T16:09:55+00:00

I have two calls of event_wait. Thread 1: Listening pipes from child processes struct

  • 0

I have two calls of event_wait.
Thread 1: Listening pipes from child processes

        struct epoll_event *ev;
        struct EpollStub stub[pool->plugins.count];
...
        epollfd = epoll_create1(0);
        if (epollfd == -1) {
                return -1;
        }
        ev->events = EPOLLIN;
        for(int i=0;i<plugins->count;i++) {
             inf = &plugins->stp[i];
             stub[i].type = EREAD_STAP;
             stub[i].pointer = inf;
             ev->data.ptr = stub+i;
             if (epoll_ctl(pool->epollfd, EPOLL_CTL_ADD, inf->fd, ev) == -1) {
                 close(epollfd);
                 return -1;
             }
        }
        do {
            n = epoll_wait(pool->epollfd, evs, EPOLL_EVENTS_MAX, -1);
            for(int i=0;i<n;i++) {
                ev = evs + i;
                struct EpollStub *stub = (struct EpollStub *)ev->data.ptr;
                if(stub->type!=EREAD_STAP) {
                    #ifdef __MDEBUG
                    printf("EREAD: Wrong event: %d\n",stub->type);
                    #endif
                    continue;
                }
                else {
    //            inf = (struct StpInfo*)ev->data.ptr;
                    inf = (struct StpInfo*)stub->pointer;
                    fd = inf->fd;
                    #ifdef __MDEBUG
                    printf("EREAD fd: %d\n",fd);
                    #endif
///do something here
                    } 
    ....

Thread 2: Listening clients sockets

    struct epoll_event ev;
    pool->epollfd = epoll_create1(0);
    if (pool->epollfd == -1) {
       return -1;
    }
    ev.events = EPOLLIN;
    for(int i=0;i<pool->sockets.count;i++) {
        struct EpollStub *stub = &pool->sockets.stub[i];
        stub->type = EACCEPT_CONN;
        stub->pointer = pool->sockets.fd[i];
        ev.data.ptr = stub;
        if (epoll_ctl(pool->epollfd, EPOLL_CTL_ADD, (int)stub->pointer, &ev) = -1) {
             return -1;
       }
    }
...

    cfd = epoll_wait(pool->epollfd, &ev, 1, -1);
    if(is_working(pool,cfd)) {
        struct EpollStub *stub = (struct EpollStub *)ev.data.ptr;
        if(stub->type!=EACCEPT_CONN) {
            #ifdef __MDEBUG
            printf("EACCEPT: Wrong event: %d\n",stub->type);
            #endif
        }
        else {
            #ifdef __MDEBUG
            printf("EACCEPT fd: %d\n",(int)stub->pointer);
            #endif
            break;
///do something here
        }
    }
    ....

kernel: opensuse-3.1.0-1.2-desktop
They get events from each other. I made EpollStub just to be shure that they get. Without this first event returns a pointer second a handle, and the result is a segmentation fault when recieve descriptor and use it as a pointer.
I do not think this is normal behavior. This is a bug in the kernel or where am I wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:09:56+00:00Added an answer on May 27, 2026 at 4:09 pm

    It’s a bug in your code. You have confused pool->epollfd with epollfd in a few places, for example:

        epollfd = epoll_create1(0);
        if (epollfd == -1) {
                return -1;
        }
        ev->events = EPOLLIN;
        for(int i=0;i<plugins->count;i++) {
             inf = &plugins->stp[i];
             stub[i].type = EREAD_STAP;
             stub[i].pointer = inf;
             ev->data.ptr = stub+i;
             if (epoll_ctl(pool->epollfd, EPOLL_CTL_ADD, inf->fd, ev) == -1) {
                 close(epollfd);
                 return -1;
             }
        }
        do {
            n = epoll_wait(pool->epollfd, evs, EPOLL_EVENTS_MAX, -1);
    

    You create epollfd, but then modify pool->epollfd and wait on that. If you have two different event sets, you need to use the two different epoll fds.

    The epoll mechanism is completely thread-agnostic. It doesn’t bind events or sets to threads. Any thread can add or remove a descriptor to or from a set. Any thread can get events for any set.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a event handler which makes two AJAX calls to the server:
I have two destinations now and the first calls a SOAP webservice. I want
I have two services, one that calls another. Both are marked as singletons as
I have two methods -a and -b. -a calls sometimes -b, and -b sometimes
I have a form that calls on two separate models. My validation works correctly
I have an IF statement that consists of two separate function calls passing values
I have an activity which needs to make two remote server calls. The first
I have getRuntime().exec() calls in my program; however, two of them will not work:
I have a helper function, which basically calls CompareTo on two objects, but does
I have two tables, let's call them meetings and phone calls. They both implement

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.