Sponsored Content
Top Forums Programming asynchronous control of threads Post 88792 by Corona688 on Tuesday 8th of November 2005 06:32:21 PM
Old 11-08-2005
asynchronous control of threads

I am attempting to build a library that is transparent to the client code. A shared resource is used by many threads with their own synchronization code, but every once in a while, ALL threads need to be stopped for some background control thread to update this resource before proceeding. I have tried many solutions, all of which have given me code that almost works...
  • Total synchronization -- a mutex controls each and every access to the resource. This is very inefficient because so much time is spent arbitrating which thread gets to access the resource, and most of the time this is overkill -- arbitration isn't needed a lot of the time, most things can safely happen in parallel.
  • Signals -- this one is painfully close to working brilliantly, but every once in a while signals go somewhere they're not supposed to. There seems no way to guard against this, and most advice I see in the literature boils down to "Don't mix signals and threads". And there's worse -- I've had pthread_kill hang on me.
  • mprotect -- a variation on signals, but theoretically more safe since the signal originates in the thread that needs to be controlled... at least delivery to the correct thread is guaranteed. Give threads a custom stack, a signal handler that waits on some sort of queue, and a spare signal stack, then set the stack as PROT_NONE when you want threads to halt. Does not work. Signals can't be caught when the stack can't be written or read, even when there's an extra signal stack available.
  • longjmp -- Give threads custom stacks and have threads save their status occasionally with setjmp and longjmp. When needed, instead of suspending threads, kill them dead, then create new ones to take their place and prerecorded state via longjmp. Does not work. There seem to be inconsistences between the stack of new threads and the stack left by the old thread.
I've got a few ideas left, but none of them are particularly elegant, all involving some sort of regimented system to control access or kernel-level thread calls. I was hoping to do this transparently. Is this impossible under pthreads?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Asynchronous I/O

Hello Please help... Asynchronous I/O ~ is it a default or needed to be enable in Solaris OS? (Solaris 8) If needed to be enable, can anyone please show me how? Thank you (2 Replies)
Discussion started by: april04
2 Replies

2. UNIX for Advanced & Expert Users

Asynchronous I/O on sockets

Hi there, I wonder if there is a (free) UNIX that support asynchronous I/O on sockets. The Linux 2.6 kernel has supports for aio, but not for socket I/O. Anyone has some UNIX distros with aio for me ? Thx Mad (2 Replies)
Discussion started by: MadCoder
2 Replies

3. UNIX for Dummies Questions & Answers

threads

i am tring to sort lots of data thats in many columns by just one column but, if I use sort +16 inputfile the column fluctuates because some of the rows have spaces etc within the text, so the end result is just a mess as it jumps around the columns depending whether it has spaces or not ....ie... (2 Replies)
Discussion started by: Gerry405
2 Replies

4. Shell Programming and Scripting

execute remote script asynchronous

Does anyone know how to execute remote script asynchronously? Here is my command TargetList=$testmaker/config/prod_domain.list for targethost in `cat $TargetList`; do rsh $targethost -l bvuser "$HOME/var/script-root/afp/bin/run_nrtp_cache_flush.sh $appName" done (1 Reply)
Discussion started by: leemjesse
1 Replies

5. UNIX for Advanced & Expert Users

Threads and Threads Count ?

Hi all, How can I get the list of all Threads and the Total count of threads under a particular process ? Do suggest !! Awaiting for the replies !! Thanks Varun:b: (2 Replies)
Discussion started by: varungupta
2 Replies

6. Shell Programming and Scripting

Asynchronous shell scripts question - newbie

Hi All, I am fairly new to UNIX and very new to this forum too. This is my first post here. Here is my scenario - I have 3 scripts script1, script2 and script3. I want to start script1 and script2 asynchronously. Upon completion of both scripts script1 and script2, i want to fire the last... (4 Replies)
Discussion started by: taskeen21
4 Replies

7. AIX

Asynchronous I/O on AIX and DB performance

Hi, I would like to hear your thoughts about this. We are running our Data warehouse on DB2 DPF (partition environment) and I have notice that sometimes we hit the Asynchronous-I/O-Processes peak. DB2 relies heavily on Asynchronous I/O so I would believe this has an negative impact.We are... (10 Replies)
Discussion started by: arizah
10 Replies

8. Solaris

Asynchronous I/O

Hi Guys, I am running Solaris 10 on T4 sparc server. How do I see if the O/S is using asynchronous I/O or DirectIO? Thanks in advance. (1 Reply)
Discussion started by: Phuti
1 Replies

9. Programming

Asynchronous communication between master and slave threads

I am writing a process that has a master thread and a set of slave threads. Master thread is supposed to get jobs dynamically and assign to slave thread which is free. Master also get results back from slaves once a job is done. The number of slaves should be adjustable dynamically based on job... (1 Reply)
Discussion started by: tamil.pamaran
1 Replies

10. Solaris

Looking for driver for SunSAI/P 3.0 (Serial Asynchronous Interface) card X2156A

I'm looking for driver for SunSAI/P 3.0 (Serial Asynchronous Interface) card X2156A for Solaris. It used to be on sun-solve, but I fail to find it on the Oracle site. Any help would be very appreciated! (1 Reply)
Discussion started by: Ira28
1 Replies
thr_min_stack(3C)					   Standard C Library Functions 					 thr_min_stack(3C)

NAME
thr_min_stack - return the minimum-allowable size for a thread's stack SYNOPSIS
cc -mt [ flag... ] file...[ library... ] #include <thread.h> size_t thr_min_stack(void); DESCRIPTION
When a thread is created with a user-supplied stack, the user must reserve enough space to run this thread. In a dynamically linked execu- tion environment, it is very hard to know what the minimum stack requirments are for a thread. The function thr_min_stack() returns the amount of space needed to execute a null thread. This is a thread that was created to execute a null procedure. A thread that does some- thing useful should have a stack size that is thr_min_stack() + <some increment>. Most users should not be creating threads with user-supplied stacks. This functionality was provided to support applications that wanted complete control over their execution environment. Typically, users should let the threads library manage stack allocation. The threads library provides default stacks which should meet the requirements of any created thread. thr_min_stack() will return the unsigned int THR_MIN_STACK, which is the minimum-allowable size for a thread's stack. In this implementation the default size for a user-thread's stack is one mega-byte. If the second argument to thr_create(3C) is NULL, then the default stack size for the newly-created thread will be used. Otherwise, you may specify a stack-size that is at least THR_MIN_STACK, yet less than the size of your machine's virtual memory. It is recommended that the default stack size be used. To determine the smallest-allowable size for a thread's stack, execute the following: /* cc thisfile.c -lthread */ #define _REENTRANT #include <thread.h> #include <stdio.h> main() { printf("thr_min_stack() returns %u ",thr_min_stack()); } ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
attributes(5), standards(5) SunOS 5.10 12 May 1998 thr_min_stack(3C)
All times are GMT -4. The time now is 09:12 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy