PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Noms de domaine > comp.protocols.tcp-ip > select() and thread shutdown
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.protocols.tcp-ip TCP and IP network protocols.

select() and thread shutdown

Réponse
 
LinkBack Outils de la discussion
Vieux 22/03/2006, 23h15   #1
andrew queisser
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut select() and thread shutdown

I've got a UDP server thread blocking on select(). I'm wondering how to
gracefully shutdown the thread. I could use a timeout of, say, 500ms and
check a flag whether the thread should terminate.

I don't really like picking arbitrary timeouts, especially since that will
delay the shutdown of the app. Is there a better way? I'm guessing that I
could have the main app close down the socket and that would unblock the
select() and allow me to check the shutdown flag.

This is running on Windows XP now but may be on something else later on so
I'm wondering if there's a consensus solution for this problem that works
across different TCP/IP stacks.

Thanks much,
Andrew
HP


  Réponse avec citation
Vieux 22/03/2006, 23h43   #2
phil-news-nospam@ipal.net
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: select() and thread shutdown

On Wed, 22 Mar 2006 23:15:08 GMT andrew queisser <andrewdotqueisser@hp.com> wrote:

| I've got a UDP server thread blocking on select(). I'm wondering how to
| gracefully shutdown the thread. I could use a timeout of, say, 500ms and
| check a flag whether the thread should terminate.
|
| I don't really like picking arbitrary timeouts, especially since that will
| delay the shutdown of the app. Is there a better way? I'm guessing that I
| could have the main app close down the socket and that would unblock the
| select() and allow me to check the shutdown flag.
|
| This is running on Windows XP now but may be on something else later on so
| I'm wondering if there's a consensus solution for this problem that works
| across different TCP/IP stacks.

Why shut it down?

Well, obviously, you don't want to build up thousands of threads for
thousands of past clients that are long gone. Why not use a variable
amount of time that is shorter when lots of threads are running, and
is longer when few threads are running? How would you decide when to
set the "go away" flag?

--
-----------------------------------------------------------------------------
| Phil Howard KA9WGN | http://linuxhomepage.com/ http://ham.org/ |
| (first name) at ipal.net | http://phil.ipal.org/ http://ka9wgn.ham.org/ |
-----------------------------------------------------------------------------
  Réponse avec citation
Vieux 23/03/2006, 01h26   #3
andrew queisser
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: select() and thread shutdown

<phil-news-nospam@ipal.net> wrote in message
news:dvsnf712jil@news3.newsguy.com...
> On Wed, 22 Mar 2006 23:15:08 GMT andrew queisser
> <andrewdotqueisser@hp.com> wrote:
>
> | I've got a UDP server thread blocking on select(). I'm wondering how to
> | gracefully shutdown the thread. I could use a timeout of, say, 500ms and
> | check a flag whether the thread should terminate.
> |
> | I don't really like picking arbitrary timeouts, especially since that
> will
> | delay the shutdown of the app. Is there a better way? I'm guessing that
> I
> | could have the main app close down the socket and that would unblock the
> | select() and allow me to check the shutdown flag.
> |
> | This is running on Windows XP now but may be on something else later on
> so
> | I'm wondering if there's a consensus solution for this problem that
> works
> | across different TCP/IP stacks.
>
> Why shut it down?
>
> Well, obviously, you don't want to build up thousands of threads for
> thousands of past clients that are long gone. Why not use a variable
> amount of time that is shorter when lots of threads are running, and
> is longer when few threads are running? How would you decide when to
> set the "go away" flag?
>

It's a little different - there is only one thread with a single socket
handling all the UDP traffic from different clients. There is also a main
thread that knows when the application shuts down. The main thread then has
to gracefully shut down the server thread, which is probably sitting inside
select() at that moment.

Andrew


  Réponse avec citation
Vieux 23/03/2006, 01h43   #4
Rick Jones
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: select() and thread shutdown

andrew queisser <andrewdotqueisser@hp.com> wrote:
> It's a little different - there is only one thread with a single
> socket handling all the UDP traffic from different clients. There is
> also a main thread that knows when the application shuts down. The
> main thread then has to gracefully shut down the server thread,
> which is probably sitting inside select() at that moment.


If you want "portable" then you should have a pipe/connection/whatnot
between the main thread and the thread going into select(). When the
main thread wants the select thread to exit, it puts a message into
the pipe/connection/whatnot which will cause the other thread to
come-out of select().

If you simply reuse the UDP endpoint - that is have the main thread do
a sendto() the addressing info for the socket on which the select
thread is selecting - you should probably make sure that the message
contains some "magic value" that would be known only to the two
threads - say a randomly generated number stored in the shared address
space of the threads. In that way, you don't have an issue with
someone using a spoofed IP address to send your select thread a bogus
shutdown message from halfway around the globe.

rick jones
porting netperf4 from Linux/Unix to Windows.
--
Process shall set you free from the need for rational thought.
these opinions are mine, all mine; HP might not want them anyway...
feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...
  Réponse avec citation
Vieux 23/03/2006, 18h06   #5
andrew queisser
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: select() and thread shutdown

"Rick Jones" <rick.jones2@hp.com> wrote in message
news:23nUf.5161$r74.3501@news.cpqcorp.net...
> andrew queisser <andrewdotqueisser@hp.com> wrote:
>> It's a little different - there is only one thread with a single
>> socket handling all the UDP traffic from different clients. There is
>> also a main thread that knows when the application shuts down. The
>> main thread then has to gracefully shut down the server thread,
>> which is probably sitting inside select() at that moment.

>
> If you want "portable" then you should have a pipe/connection/whatnot
> between the main thread and the thread going into select(). When the
> main thread wants the select thread to exit, it puts a message into
> the pipe/connection/whatnot which will cause the other thread to
> come-out of select().
>

Thanks, I think that's what I'll do - sounds clean and I don't have to rely
on periodic wakeup. Who knows, I might think of useful messages other than
"shutdown" the main thread could send to the server thread.

> If you simply reuse the UDP endpoint - that is have the main thread do
> a sendto() the addressing info for the socket on which the select
> thread is selecting - you should probably make sure that the message
> contains some "magic value" that would be known only to the two
> threads - say a randomly generated number stored in the shared address
> space of the threads. In that way, you don't have an issue with
> someone using a spoofed IP address to send your select thread a bogus
> shutdown message from halfway around the globe.
>

I was thinking of using a separate socket hadn't occurred to me to send to
the same socket the UDP packets will come into. It might not be such a bad
idea to reuse the socket, though. Since the two threads share memory space I
can check a flag or semaphore to see if the main thread really does want to
shut down or not.

Thanks,
Andrew


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 12h07.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,15548 seconds with 13 queries