LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-20-2004, 05:41 PM   #1
LogicG8
Member
 
Registered: Jun 2003
Location: Long Island, NY
Distribution: Gentoo Unstable (what a misnomer)
Posts: 380

Rep: Reputation: 30
Exiting program w/ pthreads from sig handler


I wrote a long running server process that uses pthreads
It runs with 2 threads of execution
1) Waits for data from a device and sends data to clients
2) Waits for new clients to connect

Both threads run in an "infinite" loop servicing clients until a signal is recieved

Basic execution flows like this:

Gather resources call atexit with cleanup functions
Start thread to accept clients (blocks in accept(2))
Go into infinite loop waiting for data (blocks in poll(2))

... continues along till signal recieved

The signal handler basically just calls exit

/* This is where I lose exactly what's going on */
the functions specified to atexit run.

I haven't found any good example code. I am not sure if I am still running as
if in a signal handler or what's happening with the thread. I haven't had any
failures but that could be a coincidence.

What I was thinking might be the Right Thing
is to call setjmp in main
run normally (ie wait for signal to terminate)
longjmp from the sig handler
grab a lock on the shared data
call pthread_cancel
and then return from main
let the cleanup functions run

What is a clean way to terminate the program?
 
Old 07-29-2004, 05:56 PM   #2
Chris Parker
LQ Newbie
 
Registered: Jul 2004
Location: Houston, Texas
Distribution: Debian, Gentoo, Redhat
Posts: 17

Rep: Reputation: 0
Why not just fork like most web servers? Much easier to code for.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Do YOu Know a program Called SIG? benmay05 Linux - Software 2 06-27-2005 04:35 PM
KDE crash handler when exiting programs Klas Mandriva 9 08-29-2004 11:03 PM
Program to open .sig file marlaina1 Linux - General 2 12-27-2003 12:13 AM
exiting program loops epoo Linux - Newbie 1 12-14-2003 02:37 PM
Exiting program with CTRL-Z C++ pazvant Programming 3 11-08-2003 11:41 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration