Sponsored Content
Full Discussion: problem with threads in C
Top Forums Programming problem with threads in C Post 302481944 by jim mcnamara on Monday 20th of December 2010 09:10:43 AM
Old 12-20-2010
Assume Linux, it works pretty much the same elsewhere as well. Each thread is a process that shares some address space with the parent process, and each thread usually has about 1MB of stack space by default. There is also an imposed process limit, say 4096. We are not going near that total.

1. 100 threads == 100MB of stack space, 1000 threads == 1GB of stack space. There is a process limit on stack size, which is charged to the parent process, see ulimit.

2. Every thread requires a context switch to "run". Depending on your system cpu architecture -
For a single cpu with one core, this means for each LWP (thread or lightweight process) to get cpu you have for 100 threads:
100 == 100 context switches requested every time a quantum (time slice) elapses. Say you have a 10ms quantum. That is 100 x 100 or 10000 context switches requested every second. You are spending a lot of time doing context switches.

For 1000 LWP's you have 1000 x 1000 or 1 million possible context switches per second.
When this happens, you spend all of your time in context switching and scheduling processes.

In practice a few dozen threads should be your maximum. If you get up in the 100+ range you are going to seriously degrade performance of your app and your system overall.

Consider a vmstat or top display that shows 1000 active processes, each one wanting the cpu. Everybody is waiting, almost nobody is doing anything else but waiting.

The only time this kind of thread overload becomes feasible is the case where you have 100's of cpu cores available. Clearly you do not.
This User Gave Thanks to jim mcnamara For This Post:
 

10 More Discussions You Might Find Interesting

1. Post Here to Contact Site Administrators and Moderators

old threads

Neo, if I have an old thread that is a few months old, and a few pages back in the forum it was posted in, is it ok to 'bump' it back to the front? or, would you rather i deleted the old thread, and just create a new one? btw the thread has no replies. (2 Replies)
Discussion started by: norsk hedensk
2 Replies

2. 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

3. Solaris

threads

Hi all! 1)Is there a way to write a program that will work on both solaris and intel based machines. 2)How can I achive this for a program that creates and synchronizes three threads. Thank you. vij. (3 Replies)
Discussion started by: vijlak
3 Replies

4. UNIX for Advanced & Expert Users

How many threads do I use ?

Hi, I have a program that has two types of threads: 1) Reader threads 2) Worker Threads Readers: Their only job is to read files. They just read data from the files and put them into a buffer. They are obviously I/O intensive. Workers: These are CPU intensive. They do some computation... (5 Replies)
Discussion started by: the_learner
5 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. Programming

Threads help

Hello! I started studying studying about POSIX Threads a few days ago... so I am a little confused and I would appreciate some help! I isolated this code... and I wonder if I could use threads in it! #include <unistd.h> #endif #include <math.h> //#include "main.h" #include <sys/time.h>... (1 Reply)
Discussion started by: smurf2
1 Replies

7. Shell Programming and Scripting

Perl v5.8.5 Threads Problem

Hi Unix gurus, I am facing a threading problem in Perl. I have a worker thread in perl in which I am calling a shell script. The shell script echo's output to the Standard Output from time to time as it progresses. In the worker thread, I am unable to display the echo statement of shell... (1 Reply)
Discussion started by: som.nitk
1 Replies

8. HP-UX

%Internal DCE Threads problem (version CMA BL10+)

Hi, I have a module by the name gateway, and it core dumps and gives a cma_dump.log file which says: %Internal DCE Threads problem (version CMA BL10+), terminating execution. % Reason: dispatch: no available VP (uniprocessor) The current thread is 3 (address 0x40107c40) DECthreads... (0 Replies)
Discussion started by: vanz
0 Replies

9. Programming

Java Threads

Hi guys, I want to start studding about java threads. but the only book available on the market is "Java Threads" by O'Reilly... (0 Replies)
Discussion started by: majid.merkava
0 Replies

10. Programming

Problem with timely execution of threads...

Hi Guys, We are having one multi-threaded application. The scenario is as follows: --------------------------------- Client 1 | APP Server -------------- Client 2 ... (1 Reply)
Discussion started by: 14341
1 Replies
GLXCOPYCONTEXT()														  GLXCOPYCONTEXT()

NAME
glXCopyContext - copy state from one rendering context to another C SPECIFICATION
void glXCopyContext( Display *dpy, GLXContext src, GLXContext dst, unsigned long mask ) delim $$ PARAMETERS
dpy Specifies the connection to the X server. src Specifies the source context. dst Specifies the destination context. mask Specifies which portions of src state are to be copied to dst. DESCRIPTION
glXCopyContext copies selected groups of state variables from src to dst. mask indicates which groups of state variables are to be copied. mask contains the bitwise OR of the same symbolic names that are passed to the GL command glPushAttrib. The single symbolic constant GL_ALL_ATTRIB_BITS can be used to copy the maximum possible portion of rendering state. The copy can be done only if the renderers named by src and dst share an address space. Two rendering contexts share an address space if both are nondirect using the same server, or if both are direct and owned by a single process. Note that in the nondirect case it is not necessary for the calling threads to share an address space, only for their related rendering contexts to share an address space. Not all values for GL state can be copied. For example, pixel pack and unpack state, render mode state, and select and feedback state are not copied. The state that can be copied is exactly the state that is manipulated by the GL command glPushAttrib. An implicit glFlush is done by glXCopyContext if src is the current context for the calling thread. NOTES
A process is a single execution environment, implemented in a single address space, consisting of one or more threads. A thread is one of a set of subprocesses that share a single address space, but maintain separate program counters, stack spaces, and other related global data. A thread that is the only member of its subprocess group is equivalent to a process. ERRORS
BadMatch is generated if rendering contexts src and dst do not share an address space or were not created with respect to the same screen. BadAccess is generated if dst is current to any thread (including the calling thread) at the time glXCopyContext is called. GLXBadCurrentWindow is generated if src is the current context and the current drawable is a window that is no longer valid. GLXBadContext is generated if either src or dst is not a valid GLX context. SEE ALSO
glPushAttrib, glXCreateContext, glXIsDirect GLXCOPYCONTEXT()
All times are GMT -4. The time now is 03:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy