Sponsored Content
Top Forums Programming help me out with my threaded c++ mudbase - c++, pthread_cond_wait Post 302133670 by porter on Friday 24th of August 2007 03:40:14 PM
Old 08-24-2007
Threads and signals are a bad mix.

In a threaded program you should

(a) have one thread devoted to receiving signals for the process using sigwait, this would then deal with each signal in an orderly manner. This will deal with all signals targetted at the *process*, (SIGINT, SIGQUIT etc). Do a SIG_BLOCK for all these signals in every other thread or before you create those threads so they inherit the signal mask.

(b) set up pthread_cleanup_push/pthread_cleanup_pop to protect each group of local variables to cope with SIGSEGV etc. Set up a single signal handler in the application for SIGSEGV etc that calls pthread_exit(PTHREAD_CANCELLED) or similar.

Also note that some compilers, eg g++ don't destruct C++ objects as they go out of scope during a thread cancellation.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Threaded Discussions for Webpages

Dear All, I run a website for a non-profit. Does anyone know where I can get free or cheap software to run threaded discussions for our website? Our website is obviously running off a unix platform. Thanks (4 Replies)
Discussion started by: evertk
4 Replies

2. Programming

Threaded 'find' utility

I need to modify my version of find in unix and get it to create and use two POSIX threads to carry out concurrent finding operations. How do i get about doing this>? If anyone could help me it would be much appreciated. Thanx Mariuca (1 Reply)
Discussion started by: mariuca
1 Replies

3. Programming

threaded merge sort help

I am working on a merge sort of two files of integers, and am fuzzy on some of the logic\syntax. I need two threads, each of which will open a file, read its contents into an array, and then sort the array using qsort. One thread will operate on file f1.dat(10000 numbers) and leave its sorted... (0 Replies)
Discussion started by: AusTex
0 Replies

4. AIX

multi threaded program is hanging

I have a Multithreaded program which is hanging on AIX. OS Version: AIX 5.2 and thread library version : 5.2.0.75 We Initiate the process with 50 threads..when we are disconnecting from the process it hangs.There is lots of other stuff involved here.I am just sending the piece of the problem with... (0 Replies)
Discussion started by: hikrishn
0 Replies

5. Programming

Conditional wait using pthread_cond_wait() details

Please tell me about internal functionality of pthread_cond_wait(). How it works. Whether it actually put the thread into sleep and do the context switch or use spin locking. (1 Reply)
Discussion started by: mansoorulhaq
1 Replies

6. Shell Programming and Scripting

In need of multi threaded perl assistance

I need to write a perl script to execute external programs and grab the output and return code. Each program should be killed if it has not completed within X seconds. Imagine that the script goes something like this : @commands = &get_commands(); foreach $cmd (@commands) { $pid =... (4 Replies)
Discussion started by: SandmanCL
4 Replies

7. UNIX for Advanced & Expert Users

Multi-threaded encryption @ Fedora 11

Hello, are any of the encryption programs capable of true multi-threading ? Friend of mine tells me that he's been running some testing on Fedora 11 and that the kernel doesn't support multi-threading at that level. I've been looking into TrueCrypt, encfs and both calm to support... (0 Replies)
Discussion started by: TehOne
0 Replies

8. Linux

Multi-threaded encryption @ Fedora 11

Hello, are any of the encryption programs capable of true multi-threading ? Friend of mine tells me that he's been running some testing on Fedora 11 and that the kernel doesn't support multi-threading at that level. I've been looking into TrueCrypt, encfs and both calm to support... (1 Reply)
Discussion started by: TehOne
1 Replies

9. Programming

multi-threaded memory leak

Hello All : I write a .c program to test the exactually resource the memory leak as follows: 1 #include <stdio.h> 2 #define NUM 100000 3 void *Thread_Run(void * arg){ 4 //TODO 5 //pthread_datch(pthread_self()); 6 int socket= (int)arg; 7 ... (1 Reply)
Discussion started by: aobai
1 Replies

10. Shell Programming and Scripting

Need threaded python script

I have a single threaded bash script that I am using to create secgroup rules in openstack. The process to add the rules is taking forever. Any of you python gurus know how to convert this bash script into a thread python script? Thanks in advanced. create-secgroup-rules.sh: #!/bin/bash cat ... (2 Replies)
Discussion started by: stovie1000
2 Replies
sigsuspend(2)							System Calls Manual						     sigsuspend(2)

NAME
sigsuspend - wait for a signal SYNOPSIS
DESCRIPTION
The function replaces the current signal mask of the calling thread with the set of signals pointed to by and then suspends the thread until delivery of a signal whose action is either to execute a signal-catching function or to terminate the process. This will not cause any other signals that may have been pending on the process to become pending on the thread. If the action is to terminate the process then will never return. If the action is to execute a signal-catching function, then will return after the signal-catching function returns, with the signal mask restored to the set that existed prior to the call. It is not possible to block signals that cannot be ignored. This is enforced by the system without causing an error to be indicated. RETURN VALUE
Since suspends thread execution indefinitely, there is no successful completion return value. If a return occurs, -1 is returned and is set to indicate the error. ERRORS
The function will fail if: A signal is caught by the calling process and control is returned from the signal-catching function. sigmask points to an invalid address. The reliable detection of this error is implementation-dependent. APPLICATION USAGE
Threads Considerations Since blocked signal masks are maintained at the thread level, modifies only the calling thread's blocked signal mask. suspends only the calling thread until it receives a signal. If other threads in the process do not block the signal, the signal may be delivered to another thread in the process and the thread in may continue waiting. For this reason, the use of sigwait(2) is recommended instead of for multi-threaded applications. For more information regarding signals and threads, refer to signal(5). LWP (Lightweight Processes) Considerations modifies only the calling LWP's signal mask and suspends only the calling LWP until receipt of a signal. AUTHOR
was derived from the IEEE POSIX 1003.1-1988 Standard. SEE ALSO
pause(2), sigaction(2), sigpending(2), sigprocmask(2), sigsetops(3C), sigwait(2), signal(5). CHANGE HISTORY
First released in Issue 3. Entry included for alignment with the POSIX.1-1988 standard. STANDARDS CONFORMANCE
sigsuspend(2)
All times are GMT -4. The time now is 06:06 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy