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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:30:15+00:00 2026-06-01T22:30:15+00:00

I am working on a pthread multi-threaded code and each thread is calling read()

  • 0

I am working on a pthread multi-threaded code and each thread is calling read() on a file descriptor. read() is a blocking call so it waits for data. But i want it to wait only for 3 secs to wait for data.

I thought of using alarm() and hadling SIGALRM but if I raise alarm in one thread, all the threads will got that SIGALRM signal and all of them will relinquish read. How can i do it?

  • 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-01T22:30:16+00:00Added an answer on June 1, 2026 at 10:30 pm

    Use the select call for that. It has one argument that allows you to specify a timeout.

    The Linux man page for select has a sample usage, and you’ll find lots of examples here and elsewhere on the web.

    If you’re not worried about portability, there are more modern/featureful options.

    • For Linux, there’s the epoll facility. The man page has sample code, this question lists a couple of blogs with other usage information.
    • For some of the *BSDs (and Mac OS X), there’s kqueue.
    • Solaris has an Event Completion Framework
    • AIX has a pollset interface.
    • For Windows, please see: What is the best epoll/kqueue/select equvalient on Windows?

    You might want to look into libraries to abstract all that out. libevent is worth a look, and wraps most of the above OS-specific interfaces.

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

Sidebar

Related Questions

i'm working with a multi-threaded program (using pthreads) that currently create a background thread
I am working on some code which uses the pthread and semaphore libraries. The
I'm trying to write some multi-threaded code in C++, but I can't seem to
I have a multi threaded program in C that was working well but was
I'm currently working on a multi-threaded application that would be deployed on arm and
I'm working on a multithreaded (pthread based) project. The project uses a library that
New to pthread programming, and stuck on this error when working on a C++&C
A part of an application I'm working on is a simple pthread-based server that
I'm working on this example with C threaded server and java client. This is
I'm working on a project in C that involves creating a user-level thread library

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.