Project

General

Profile

Bug #7419

eventfd wrongly blocks writers in semaphore mode

Added by Robert Mustacchi over 4 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Normal
Category:
kernel
Start date:
2016-09-27
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:
Gerrit CR:

Description

While reading through the eventfd souce, I saw a set of conditions which would cause it to leave a writer blocked even when there is capacity of the incoming data.

This test program runs successfully on Linux, but hangs on illumos:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/eventfd.h>

int efd;

void *writer(void *arg)
{
        uint64_t val = 2;
        int res;

        res = write(efd, &val, sizeof (val));
        printf("write: %d\n", res);
        return (NULL);
}

int main()
{
        pthread_t t;
        uint64_t val = 0xfffffffffffffffd;

        efd = eventfd(0, EFD_SEMAPHORE);

        write(efd, &val, sizeof (val));

        pthread_create(&t, NULL, writer, NULL);
        sleep(1);
        read(efd, &val, sizeof (val));
        printf("read done\n");
        pthread_join(t, NULL);
        exit(0);
}

eventfd_read will only signal writable state if the old value was EVENTFD_VALMAX.

#1

Updated by Electric Monk over 4 years ago

  • Status changed from New to Closed

git commit 860884eb865676dc41b8ef65c09df94f7c3f14ef

commit  860884eb865676dc41b8ef65c09df94f7c3f14ef
Author: Patrick Mooney <pmooney@pfmooney.com>
Date:   2016-10-11T17:08:19.000Z

    7419 eventfd wrongly blocks writers in semaphore mode
    Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
    Reviewed by: Bryan Cantrill <bryan@joyent.com>
    Approved by: Dan McDonald <danmcd@omniti.com>

Also available in: Atom PDF