02-08-2012
pthread_cancel failure
I'm running a simple web server and seem to be having a problem canceling sessions.
When a new request is received I start a thread to handle that session's requests. Since I want to keep the pipe open for a long time - 10 minutes or maybe 2 hours - I also have a session manager that checks for inactivity. When the time is up I want to cancel the session thread.
The problem is I don't think the thread is getting canceled and I'm leaking memory with zombie sessions. I've set the threads for asynchronous cancellation but I'm getting a return code of 3 and I should get all zeroes per the manual.
Server code:
pthread_create( &NewSessionThread, NULL, &HTTP_Server_Session, (void *) (NewSessionListItem));
Session code:
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, oldstate);
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, oldtype);
Session manager code:
CancelResult = pthread_cancel(SessionPointer->SessionThreadID);
fprintf(CrashLog, "HTTP pthread cancellation result (0, success - other not): %d\n", CancelResult);
if (CancelResult == 3)
fprintf(CrashLog, "HTTP pthread cancellation error: %s\n", strerror(errno));
Logfile sample result:
HTTP pthread cancellation result (0, success - other not): 3
HTTP pthread cancellation error: Success
I guess I have three questions:
Why isn't the cancellation working?
Why is the error string “Success” when the result is not 0?
How should I try to fix it?
Thanks!
10 More Discussions You Might Find Interesting
1. Programming
Hi,
I am using gmake to compile a c program with a makefile. The make file runs ld. I get the following error
jsh1035c:/users/egate453/admegate/kapil/samples $ gmake -e -f GNUmakefile queue_c
gmake -f ./GNUmakefile queue_c in_objdir=1 build_root=/users/egate453/admegate/kapil/samples... (2 Replies)
Discussion started by: handak9
2 Replies
2. Programming
Hi all,
I am working on a piece of multi threaded code, where I have a main thread looping in increments of 5ms, while it is waiting on a helper thread which is writing to a remote location. This helper thread keeps updating the main thread about progress of the write operation and the moment we... (1 Reply)
Discussion started by: ravneetd
1 Replies
3. Programming
Hello!
First of all, sorry for my English, I'm not a native English speaker.
I know, that printf() function uses write() function. "man cancellation" says that write() function is a cancellation point. But when I call pthread_cancel() for my thread, which calls printf() in infinite cycle, it... (4 Replies)
Discussion started by: prankster
4 Replies
4. UNIX for Advanced & Expert Users
aix 4.3
I get the following error from the errpt log
BD797922 0306170008 P H enclosure0 SUBSYSTEM FAILURE
I'm not clear on this kind of error. It never happened to me.
What do this errors mean, and how do I clear or solve them?
Any help is appreciated. (2 Replies)
Discussion started by: andwhat
2 Replies
5. Linux
Hi all
I used a dual boot operating system and it works fine for me. Now , i install a Ati radeon 9250 Agp card on my system and this results in boot failure of fedora 6. The graphics card is working fine with windows XP , i.e i have no compatibility issues.The system also refuses to boot when i... (2 Replies)
Discussion started by: joshighanshyam
2 Replies
6. UNIX for Advanced & Expert Users
I tried to execute a sample pthread program to cancel a newly created one using pthread_cancel(). but using valgrind on my code shows some memory leak.
My Code:
#include "iostream"
#include "unistd.h"
#include "pthread.h"
#include "signal.h"
using namespace std;
void handler(int);
void*... (4 Replies)
Discussion started by: kcr
4 Replies
7. Solaris
Earlier live upgrade from solaris 8 to solaris 10 5/08 was not permitted . Later by document 250526 dated Feb 2009 , it permitted and fllowing s8p7zip.tar and following solution 206844 .
While installing SUNWluu,SUNWlur,SUNWlucfg , I had a partial failure . But pkginfo shows the information... (5 Replies)
Discussion started by: Hitesh Shah
5 Replies
8. UNIX for Advanced & Expert Users
Usually when su rejects an attempt to switch user it responds with "Sorry" but with a certain username on some unix servers the response is "Killed". I'm guessing the su accepted the username/password but refused to spawn child shell with the specified username. What's causing this and what has to... (8 Replies)
Discussion started by: twk
8 Replies
9. UNIX for Dummies Questions & Answers
hi power went out. next day unix sco wont boot up error code 303. any help appreciated as we are clueless. (11 Replies)
Discussion started by: fredthayer
11 Replies
10. Solaris
Hi Team,
Am new to solaris. There is a script in the crontab that issues backup at a scheduled time. It fails alway. here are some logs. Can anyone please help why backup fails.:
sdpuser@sdp3a>dmesg ... (4 Replies)
Discussion started by: andersonedouard
4 Replies
LEARN ABOUT LINUX
pthread_testcancel
PTHREAD_TESTCANCEL(3) Linux Programmer's Manual PTHREAD_TESTCANCEL(3)
NAME
pthread_testcancel - request delivery of any pending cancellation request
SYNOPSIS
#include <pthread.h>
void pthread_testcancel(void);
Compile and link with -pthread.
DESCRIPTION
Calling pthread_testcancel() creates a cancellation point within the calling thread, so that a thread that is otherwise executing code that
contains no cancellation points will respond to a cancellation request.
If cancelability is disabled (using pthread_setcancelstate(3)), or no cancellation request is pending, then a call to pthread_cancel() has
no effect.
RETURN VALUE
This function does not return a value. If the calling thread is canceled as a consequence of a call to this function, then the function
does not return.
ERRORS
This function always succeeds.
CONFORMING TO
POSIX.1-2001.
EXAMPLE
See pthread_cleanup_push(3).
SEE ALSO
pthread_cancel(3), pthread_cleanup_push(3), pthread_setcancelstate(3), pthreads(7)
COLOPHON
This page is part of release 3.27 of the Linux man-pages project. A description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
Linux 2008-11-17 PTHREAD_TESTCANCEL(3)