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 8074127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:33:14+00:00 2026-06-05T14:33:14+00:00

I have a driver that wants to send notification to the user about a

  • 0

I have a driver that wants to send notification to the user about a status change. In the current implementation it uses the proc filesystem to do so. The read process loops around a read() to the proc filesystem. The read() blocks with wait_event_interruptible() until the kernel gets an interrupt which causes the write_new_data() function to call wake_up_interruptible(). Here’s the basic code (removed all unneeded clutter):

static int flag=0;
DECLARE_WAIT_QUEUE_HEAD(info_wq);

//user process call read() on /proc/myfile to get to this function
int my_proc_read (struct file *filp, char *buf, size_t count, loff_t *pos)
{
    wait_event_interruptible(info_wq, flag != 0);
    flag = 0;

    //copy buffers to user
    return 0;
}


//when an interrupt comes it schedules this function on the systems' work queue
void write_new_data ()
{
    //fill buffer with data
    flag = 1;
    wake_up_interruptible(&info_wq);
}  

Now consider the following flow:

  1. User process calls read(), then waits.
  2. interrupt occurs -> write_new_data() is called. writes data and calls wake_up_interruptible().
  3. read() is awaken, reads data but process has not rerun read (wasn’t scheduled
    to run, didn’t get to it because of the next interrupt…).
  4. interrupt occurs -> write_new_data() is triggered again, calls wake_up_interruptible() but no waiting thread is waiting…
  5. process calls read and blocks.

Note: this all happens on a uni-processor system. Also there is only one thread reading and one thread writing new data.

How can I avoid missing the second interrupt? (One solution is to use netlink sockets but I was wondering if there is a way to do it in /proc land)

  • 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-06-05T14:33:15+00:00Added an answer on June 5, 2026 at 2:33 pm

    Since the interrupt can occur between the call to wait_event_interruptible and flag = 0, it would affect the flag variable in an unwanted way.

    Note that even on a UP machine, the kernel could be preemptive depending on the configuration, and that code would be affected as a result.

    Also, I advice to not use a simple ‘int’ flag. Instead, you should use atomic_t and atomic_dec/inc_* operations. See the implementation of completions inside the kernel, it does something similar to what you are doing here.

    About the question itself:

    If you’ll look in the code of wait_event_interruptible you’ll see that the sleep doesn’t take place if the condition is true – so your problem is a non-problem.

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

Sidebar

Related Questions

I have a program that send a document to a pdf printer driver and
i have to make a device driver that returns a random number between 1
I have a printer that doesn't have the driver for my windows server 2008,
I have noticed that when I call lseek64 on my block device driver file
I have a selenium test that looks like require 'spec_helper' driver = Selenium::WebDriver.for :firefox
I have written a udev rule that call a script to send email when
Background: I have a gtk client that uses twisted and perspective broker to perform
I have a set of user controls on a page that are dynamically loaded
I have a D-Link DWM-156 3G USB modem that I want to send AT-commands
I have written a udev rule that call a script to send email when

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.