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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:49:14+00:00 2026-06-01T01:49:14+00:00

I am programming a http server. There is the main daemon spawning a bunch

  • 0

I am programming a http server. There is the main daemon spawning a bunch of listeners, which are threads or processes, depending on user settings. Upon creation of a listener, the socket descriptor is passed to it, and its job is just to listen for connections (duh). A semaphore is wrapping the call to listen as to avoid the thundering herd effect.

My problem is how to quit the server. In this situation, where the listeners are blocked on a semaphore, how does the daemon is going to tell them to close? The daemon can’t just kill them, maybe someone is responding to a request…

I want to keep the design as simple as possible, but I can’t find a solution to this problem.

Here are some ugly workaround:

  • Set a timeout for the semaphore. Wake up. Should I close? No? Ok, back to sleep;
  • Just kill them;
  • Array of booleans in shared memory, meaning responding/blocked, the daemon kills accordingly. The best so far, but not so simple.

What do you say?
Thanks.

  • 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-01T01:49:15+00:00Added an answer on June 1, 2026 at 1:49 am

    A clean way to solve this problem is to make each listener wait on two semaphores. The first one it the current one you now use, and a second one, that when become signaled, means it’s time to quit. I believe your system is linux since you used the term daemon. The function select does just that – waits on multiple objects (file-descriptors like), and returns when one of them becomes signaled. You also know from the function which one got signaled, so here is your solution.

    On Windows the function is WaitForMultipleObjects()

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

Sidebar

Related Questions

There are a bunch of different Scheme interpreters available for the Mac: http://www.dmoz.org/Computers/Programming/Languages/Lisp/Scheme/Implementations/ Which
I've implemented a simple multi-threaded HTTP server for my programming assignment a couple weeks
I have an HTTP server which is in our internal network and accessible only
I'm programming an Android multi-player game, which basically consist of a server where the
For some reason my submit button isn't centered. http://prime.programming-designs.com/test_forum/viewboard.php?board=0 #submitbutton{ margin: auto; border: 1px
I was learning socket programming and tried to design a basic http client of
http://developer.apple.com/iphone/library/samplecode/TableSearch/index.html I am a just 2 days old in iphone programming. I downloaded the
I am experimenting with OpenCL programming. I was following the article in http://www.thebigblob.com/getting-started-with-opencl-and-gpu-computing/ When
I have used emacs for erlang programming. According to http://emacswiki.org/emacs/CompileCommand , I have configure
We are testing a DSL modem's web pages (the HTTP server is running on

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.