Programming :: Thread Scheduling And Signalling
Mar 23, 2010
I have a program which is uses sigaction to register for a SIGIO signal (for incoming data on a fd) with an appropriate event handler. I also create a new detached thread 'B' that does some work with the received data. Normally the thread B runs properly. But when my event handler is called (because a there is new incoming data), after the event is handled, the thread B is not called immediately. There is a noticeable delay of the order of many seconds before it is scheduled again .During this delay, my program is doing nothing.
What am i doing wrong? Is there someway i can run thread B as soon as the event is handled (and assuming no other work is to be carried out)?
View 3 Replies
ADVERTISEMENT
May 4, 2011
I have a timer thread, and when it expires, it sets a flag. The only problem is, if any higher priority thread comes in between, then the timer is not expired in real time.Thus i want to set a highest priority to my thread. Now, i know 2 algos, which can make my thread in real time are: SCHED_FIFO and SCHED_RR.
So, here are my queries: 1) Which scheduling algo is best suited for this purpose? 2) Is it guaranted to work in real time if i use that algo (you suggest in 1) and set the max_priority by getting the maximum settable priority for that particular algorithm using, int sched_get_priority_max(int policy);
View 2 Replies
View Related
Sep 9, 2009
I am new to thread programming. I need to generate one thread in one process using posix thread. Which scheduling and priority do i need to use? I want to generate the thread with the lowest priority. As i know there are 3 scheduling policy available SCHED_FIFO, SCHED_RR or SCHED_OTHAR.
View 1 Replies
View Related
Jun 13, 2011
Not sure if I have landed in right place for this question .Problem FacedI have 30-40 heavy load (Memory operations on heap) processor running with each having 30-40 threads.In one of the thread (of each process), I have file locking operation as explained below (say in thread T1)Step 1 - Lock the file using fcntl(SETWLK) on file f1, Basically using wait lock.Step 2 - Read/write data from another file f2.Step 3 - unlock the file f1.As the memory occupied by process increased, the swap area used will reduce - this continues for a long amount of period. When the free swap space is reduced to 100 MB free out of 2 G and VIRT reduces to 120MB free out of 17G, for T1 thread, Step 3 is not scheduled for more than 300 seconds after Step 1 and 2.
I want to understand why this behavior is present - as per my understanding scheduling will occur within micro-seconds and we can expect that the T1 thread of all process should be scheduled without too much delay.Additional InfomationMachine Info : (uname -a), Linux linux 2.6.16.46-0.12-smp#1 SMP Thu May 17 14:00:09 UTC 2007 x86_64 x86_64 GNU/LinuxMemory Info :Total Memory is 16GB + Swap Memory is 2GBI want to know why this behavior is observed in SUSE
View 4 Replies
View Related
Dec 25, 2010
I am going to use "pthread_setaffinity_np" to bind a thread to a specific core. My application has two threads. I have used mutex to assign a specific id to each thread and then bind that thread to a core different from another core. but it seems that the os assigns both thread to one core.What should I do to bind each thread to a specific core?
View 4 Replies
View Related
May 30, 2011
I'm trying to write a GUI text encryption application. I wrote the encryption system in a No GUI application like this::
[Code]...
Now I'm trying to write a GUI version, using the same algorithm. Here goes a rough image of my main window code. If you scroll down you'll observe a coloured part. As you see, the text in the first textbox gets copied into clipboard. That is the part where my encryption system should encrypt the data in the clipboard, and copy it again, and later on the new data will be pasted. How am I supposed to write that? If I have to use another signal, what is the receiver of that signal?
[Code]...
View 5 Replies
View Related
Sep 28, 2010
A simple TCP based chat server could allow users to use any TCP client (telnet, for example) to communicate with each other. For this question you should consider a single process, single thread server that can support exactly 2 clients at once, the server simply forwards whatever is sent from one client to the other (in both directions). Your server must not insist on any specific ordering of messages as soon as something is sent from one client it is immediately forwarded to the other client. As soon as either client terminates the connection the server can exit
View 4 Replies
View Related
Feb 10, 2010
i think we can simulate preemption by using 2 different priority thread, am i true? I just try these scenario :
1. Create Thread A with priority 99 , SCHED_FIFO..
2. Create Thread B with priority 4 , SCHED_FIFO
Thread A started and doing some busy work.. I guess that Thread B wouldn't start until thread A finished, but I get thread B can run before Thread A finished (It just like a common task switching).. I'm sure my 2 thread has right priority. and if thread B is doing some work and if i yield it to thread A, it should preempt it but this doesnt happen, do someone kno wats happening?
View 1 Replies
View Related
May 10, 2011
Does anyone know how to run 2 threads with round robin scheduling. & can we get the time of these threads when they are context switching. That means I want to know at how much time each thread is taking to run
View 3 Replies
View Related
Jan 12, 2011
I am working on a large program in C to run on Puppy Linux. I have multiple pthreads running. I want to be able to set the pthread SCHED_POLICY and priority in my program but I want a user to be able to run the program without root privilege.
Using a sticky bit and root ownership gives the user too much power because they will be able to write and compile their own scripts. Is there a way to use 'sudo' when I set the thread parameters from my program or something like this?
View 1 Replies
View Related
Jun 24, 2010
What is the quickest way to get the thread id(tid) of the current thread in linux? Specifically I use fedora 13. ...and I am talking about inside a C++ program.
View 2 Replies
View Related
Jul 2, 2010
Is there a library/system call that will return to me what CPU core a thread of execution is running on? I've looked for a bit on the net already and also in /usr/include and couldn't find one.
getcpu() and sched_getcpu() are two that I found, but when I include the appropriate header files (linux/getcpu.h, and sys/sched.h respectively), gcc says getcpu.h doesn't exist and the linker complains it cannot find the implementation in sched.h.
I'm sure I'm doing something really stupid or overthinking...
What I am doing is running an OpenMP application and specifying a list of cpu cores to run on with GOMP_CPU_AFFINITY. I want to make sure that each core is getting the same number of threads.
**UPDATE**
It seems that this code works, but only with glibc >= 2.6, and my machine has 2.5:
Code:
#define _GNU_SOURCE
#include <stdio.h>
#include <utmpx.h>
int main( void )
[Code].....
View 3 Replies
View Related
Aug 11, 2010
i created one thread in main(). I have while in thread function.
I want close the thread in main after some time. How can i close it.
View 4 Replies
View Related
Feb 16, 2010
Kernel: 2.6.24.2
System: Embedded System
I have a process and two threads running in it. Thread1 is my GUI-Thread (using FLTK) and Thread2 is running at the first 10 sec. after start.Now, I would like to make Thread2 "nicer" to Thread1, because otherwise GUI stucks sometimes. But I didn't find a solution.Is it possible to define the "niceness" of threads inside a process (to each other)? And if so, how do I have to do this?
View 2 Replies
View Related
Feb 11, 2011
I have to launch a new thread from my existing main program and pass data to it.
For now the data is simply a string value.
How I go about passing data to a new thread while it is running.
View 5 Replies
View Related
Sep 22, 2010
When I set the stack base address of the child thread using the POSIX library function "pthread_attr_setstackaddr()", I am unable to access the memory contents of its parent. The data-structures that are created on the HEAP of its parent using malloc() are either getting destroyed or unaccessible when moving to the context of the child thread. These data-structures are being passed as an argument to the child thread.Even if I make these variables global then also it is not working.pthread_attr_setstacksize(tattr, ...);stackbase = (void *) malloc(...);pthread_attr_setstackaddr(tattr, stackbase);But when I create the child thread without setting its stack base address using that pthread_attr_setstackaddr(), then it is able to access the parent's memory contents.
View 1 Replies
View Related
Jan 27, 2010
How to get list of threads of a process using C code in Linux?
View 6 Replies
View Related
Jun 10, 2010
I have done some searching around the internet and this site, but I haven't found a good way to count the context switches on a thread in a c++ program I am running. I need to know if it get swapped off of a CPU for correct timing.
View 4 Replies
View Related
Feb 21, 2010
I have created an error logger thread in my application using pthread_create(), I want this thread to have a lower priority than my application's priority so that the application would run properly. Is there an easy way to do this? I know that we can change priority for thread created with policies FIFO or RR, since I don't set the policy for my application, I don't know what to set for my thread.
View 4 Replies
View Related
Dec 14, 2010
I want to suspend/resume a thread. The library I am using is pthread.h.I am also running my application on linux.Is there any function in pthread. let me suspend a thread temporary?I have read a document in which it was mentioned thatthread does not support suspend/resume
View 4 Replies
View Related
Jan 23, 2011
I seem to only be able to set my stack size on my linux server to 15000. If I increase it to 20000 I get a Segmentation Fault. how I can get the linux OS to increase the stack size? Code: threadRet |= pthread_attr_setstacksize( &m_ThreadAttributes, 15000 );
View 8 Replies
View Related
Sep 17, 2010
I don't seem to find a conclusive answer to this one...."Is popen thread safe via pthreads?"
View 2 Replies
View Related
Jan 14, 2011
This is a client server issue where the server creates a new thread for listening to a new client, now when the thread starts execution and during its execution the server needs to pass it an object of some X class, how's that to be done?
View 4 Replies
View Related
Aug 12, 2010
I am trying to pass an array to thread program. Its printing the val[0] value but its not printing value at val[1]. Can somebody help me with this problem.
Code:
#include <unistd.h>
#include <stdlib.h>
[code]....
View 4 Replies
View Related
Jul 27, 2010
Rather than get in hot (or even slightly-above-comfortable temperature) water for reviving a closed (ca. 2007) thread without moderator permission or acquaintance of the OP personally or by proxy, I'll post this alternate solution (approach?) along with one positive real-world example illustrating how mine is easier to write and is equally reliable, if not altogether better. The thread is here. Their solution:
Code:
if [ "$myfilesize" eq "0" ];then echo "$file: the file size is zero"; else echo "$file: the file size is NOT zero"; fi (and this hangs on the output of a stat -c %s command). "Hangs" is probably a most appropriate word. The two outputs, using two different stat options, the same file, and three marginally-different command-line syntaxes I just tried gave me these: First, using their approach, I got this:
Code:
tjsfa070929-094.jpg.error: the file size is NOT zero
Even though stat gave me this
Code:
>> stat -c %s $file
[Code]...
From where I sit, getting the file type string instead of an integer, which can be equally (if not often more) accurate, makes for an easier time of setting the conditional and, maybe only in terms of a few ticks, a faster script from start to finish. I think my method is better, and proven so to the limits of my knowledge and ability here in this OP.
View 1 Replies
View Related
Mar 11, 2010
I hope someone can help me with this. I need to call the same thread multiple times, but only run one thread at a time. So what I do is create the thread which runs then drops out. Run the main loop and after some time pthread_create the same thread again. So in pseudo code
[Code]...
I always presumed if I run a thread and it reaches with a pthread_exit, then the thread was destroyed? However I've found that after I've created the thread several 100 times the programme crashes? So can anyone advise how I call the same thread over and over?
View 10 Replies
View Related
Mar 25, 2011
Where can I get the source code of quick thread?
View 1 Replies
View Related
Mar 24, 2011
I want to know, is there any way to prevent the multi-thread process from crashing if some errors (say, segmentation faults) occur in one of its child threads? I've found pthread_sigmask() function, but that does not seem to work:
Code:
#include <stdio.h>
#include <unistd.h>
[code]...
View 3 Replies
View Related
Sep 6, 2010
I'm making a programm under OpenSuse 11.1I'm using SDL and ofcourse SDL_TTF.when i render with the SDL's TTF function under main(), i have no problems, but when i render under thread i have segmentation fault.There is not exist any typing or any competition (i'm using semaphores) but even if i try to render on a local SDL_Surface i'm having the Segmentation fault...
View 2 Replies
View Related
Mar 24, 2011
I'm wondering how python's thread & fork support is compared to perl? Which one is best option among Perl and Python
View 1 Replies
View Related