Programming :: Related To Pthreads And Timers In POSIX Standard

Feb 17, 2010

I have created two threads:
Thread 1 and thread 2

In the main thread, i have put up a timer which generates a signal periodically when it expires, which reults in execution going to signal catcher function.when this function is invoked, under certain condition it goes to thread 1 and under another condition it goes to thread 2. The problem lies here that when it goes to thread2,i have a loop to process but it doesnt come out of the loop and hence from thread2, even though timer has expired.

View 2 Replies


ADVERTISEMENT

Debian :: Posix Related During Compilation?

Sep 4, 2011

I am trying to compile splasutis in my debian wheezy. ./configure run well, but during make I get the following error

make --silent all-recursive
Making all in libs
CONF    libjpeg.a

[code]....

View 7 Replies View Related

Programming :: Timersub Command - Subtracting Two Timers

Jul 28, 2011

I am using timersub to subtract two timers but the result is not what I would expect.

* My code *
struct timeval best_acquisition_time, best_at, temp_time1;
best_acquisition_time.tv_sec = 1311826027;
best_acquisition_time.tv_usec = 0;
best_at.tv_sec = 1311826026;
best_at.tv_usec = 741835;
timersub(&best_at, &best_acquisition_time, &temp_time1);
* End of Code *

When I inspect temp_time1 after timersub executes the result is:
temp_time1.tv_sec = -1;
temp_time1.tv_usec = 741835;

I expected:
temp_time1.tv_sec = 0;
temp_time1.tv_usec = -258165;

View 3 Replies View Related

Programming :: Preemption And Scheduling Of Pthreads

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

Programming :: Suspend Pthreads Without Condition

Jun 29, 2010

I just started with Pthreads and don't really know much about it. I want to suspend pthreads but apparently, there is no such function as pthread_suspend. but I don't understand why we need both mutex and condition to suspend and resume a pthread. Is it possible to suspend and resume it without using conditions?

View 1 Replies View Related

Programming :: Pthreads Return Value Valid Or Not

Jun 14, 2010

I have confusion regarding pthreads return value. All in short, is the is a valid return value ?

[source]
void * myThrRoutine(void *arg)
{
struct myStruct **myst = (struct myStruct**) arg;
cout<<"In thread "<<(*myst)->var<<(*myst)->msg<<endl;
int x = 20;
pthread_exit((void*)x);
}
[/source]

This seems to work fine on pthread_join , but I want to ensure it is not by chance.

View 1 Replies View Related

Programming :: Segfault In Program Using Pthreads

Mar 16, 2010

I am trying to write a peer to peer application in C++ using pthreads library. There are few types of nodes that run in the program. The 'beacon' nodes form the core of the network. The ordinary nodes 'join' the network by sending join requests to the beacon node. So, my program runs till the join requests and responses are received. When I try to 'connect' using connect function from the socket library, I get a segfault. I am not sure if the segfault occurs for the connect function, because sometimes the program just runs to completion. It could be an issue related to threads or memory allocation.

When I run gdb, it shows me the following:
Code:
(gdb) run b2-n00.ini
Starting program: sv_node b2-n00.ini
servant:12600> [New LWP 1]
[New LWP 2]
[New LWP 3]
[New LWP 4]
[New LWP 5]
[New LWP 6]
Before Exiting[LWP 1 exited]
procfs: fetch_registers, get_gregs line 3768, /proc/23952/lwp/1: No such file or directory.

View 6 Replies View Related

Programming :: Using Lock In OpenMP And Pthreads

Apr 14, 2011

I have a program that uses both Pthreads and OpenMP. Basically, 2 threads (Thread A and B) are created using Pthreads to do work, and in Thread A, OpenMP is used to parallelize a for loop.If I have a global variable that is accessed by the OpenMP threads and also Thread B, can I use the lock in OpenMP to ensure I have no race conditions?

View 2 Replies View Related

Programming :: Is Popen Thread Safe Via Pthreads?

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

Programming :: Synchronize 2 Posix Threads ?

Mar 15, 2011

I have 2 threads and both of them are deleting memory at the end nedded by both.

My problem is that maybe it can happen that a thread start and finish before the other one starts and so it deletes the memory nedded by the other thread. How can I synchronize them so that this can't happend.

As a design my threads look like this:

Code:

The other thread looks the same, but this isn't unoff to stop thread1 to finish before thread2 starts.

View 4 Replies View Related

Programming :: Proper Implementation Of POSIX Threads

Apr 6, 2011

I've implemented a program URL... which reads digital IF data from a radio receiver through a named pipe, measures power levels, and sends the result to stdout. The program is interactive; there is a thread that reads from stdin to watch for commands, a thread that constantly either reads data from the named pipe or throws data away, and an array of processing threads. The program uses GTK+extra to plot the signals. The IF data stream bandwidth exists at the limits of today's technology (is very very fast).

Problem Statement:The program works fine with a few bugs. I've learned since I've made it that using global state variables to coordinate threads isn't a good way of doing it. I also only had knowledge of mutexes and polled the state variable instead of using other methods.My reimplementation will use the following:

- One "Stdin Command Monitoring" thread
- One "Get data from named pipe" thread
- One post-processor thread
- N Processing threads

All threads are alive during the life of main()There are N buffers. Data will come in from the named pipe, and the "Get data" thread will write the data to an "available" buffer. When the buffer is full it will be marked as "full". There will be N processing threads, one for each buffer. When a processing threads' buffer is full, it will process the buffer and save the result to a final buffer. At the end of a number of averages, the post-processor thread will perform a final process on the final buffer and send the results to stdout.

View 2 Replies View Related

Programming :: Function Handler Is Called One Time Only Instead 2 Times If The 2 Timers Expires At A Time

Mar 2, 2011

I am using Debian linux. I have 100 timers running. If a timer expired which will generate a signal and it was mapped to a same function handler. All the timers are mapped to one function handler. The problem is if the timer expires one at a time, the function handler called at a time. But if the 2 timers expires at a time, the function handler is called one time only instead 2 times. Is it possible to invoke the function handler as many times based on timer expirary happens simultaneoulsy?

View 14 Replies View Related

Programming :: Closing / Unlinking POSIX Message Queues?

Apr 15, 2011

I have a pthread waiting forever on a POSIX message queue and then call mq_close and mq_unlink on the POSIX message queue. I've found that the pthread never wakes up from it's call to mq_receive and remains blocked indefinitely. Is there a way to wakeup all pthreads blocked on a POSIX message queue after calling mq_close/mq_unlink? The goal is to include error handling during message queue deletion to avoid leaving any pthreads blocked forever.

View 2 Replies View Related

Programming :: Find Number Of Child Processes (C / POSIX)?

May 26, 2010

I'm in the process of writing a program that is a server- it will accept connections and stuff, and spawn a child process for each. However, i've run into a small problem. I do NOT want to bother with keeping track of the processes unless i need to. So, i set SA_NOCLDWAIT (#ifdef) on a SIG_IGN to the SIGCHLD handler through sigaction interface. The standard says that it the kernel will then keep track of reaping zombie processes for me (a HUGE plus). However, upon receiving a SIGINT signal, i want to stop the server from accepting new connections (done), and then wait for there to be no new connections. I was thinking of just putting a loop like so:

Code:

while((wait(NULL) != (pid_t)-1) && errno != ECHILD);

However, I'm not *sure* that this will work, especially with SIGCHLD still ignored. So how can i tell if there are still child processes? I can't find any call like int getnumchld(pid_t proc); (i wish). Plus it would be inefficient to spin on that function anyway. OTOH, i would rather *NOT* have to do the same thing in a loop with a system("ps |...>file"); read(file); etc. either. Is there a way i can portably implement this feature (I was hoping i could run it on linux and the major BSDs, at least).

TO SUM IT UP:

How can i tell if a process has no child processes if i've SIG_IGN'd SA_NOCLDWAIT'd the SIGCHLD? Is there a _reasonably_ portable way to do so? I *don't* want to manually wait for EVERY process. Maybe only those still active at the time of SIGTERM, but that requires keeping track of the number of connections and whether those have terminated...

EDIT: Does anyone know if the above code *would* work, even with SIGCHLD ignored and the kernel cleaning up zombies *for* me? I checked the manpage and it doesn't say much.

EDIT1: Note that all of the processes are in the same process group and session. SO i can find them through this as well. Perhaps even setting the uid/gid and finding all processes run by that group?

EDIT2: i have an idea if the above isn't feasible. If there is no "elegant" way to do it, i could reduce the complexity by sending a SIGUSR1 to the whole process group. Each process would then set a flag telling it to send a SIGUSR1 in reply and send a SIGUSR2 when it is done executing. Then i could keep a count of signals. Maybe that would be *easier*. Or perhaps a count of all child processes and just a termination signal to decrement the counter.

View 2 Replies View Related

Programming :: Posix Message Queues - Communicate Between Two Threads?

Jan 3, 2011

I want to communicate between two threads, each belonging to a different process. Iam using message queues for this. I use mq_open()call. I created the queues with the same queue name starting with a '/'. But when I open the queue, the queue ID is different in both the process. What should I do so that both the process have the same queue ID?

View 1 Replies View Related

Programming :: Program Hang Stuck There Signal Handling On POSIX Message Queue UNIX C Pr

Jun 14, 2011

In a single main() function,so need signal handling. Use Posix Message Queue IPC mechanism , can ignore the priority and other linked list message,to implement the scenario:

View 1 Replies View Related

Programming :: Getting A Short Shell Script Related To PIDs?

Nov 21, 2010

how can I store the output of (ty to colucix for this line)

Code:

xprop -id $(xprop -root | awk '/_NET_ACTIVE_WINDOW(WINDOW)/{print $NF}') | awk '/_NET_WM_PID(CARDINAL)/{print $NF}'

in a variable and then pass the value of that variable to the kill command as the PID to kill?

View 3 Replies View Related

General :: Use Several Timers With Setitimer()

Mar 24, 2010

I would like to use several timers with setitimer, but I have a problem. setitimer() with ITIMER_REAL, send always SIGALRM. Example:

Code:

#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>

[code]....

In this example, I configure two timers, but setitimer use SIGALRM, so only one timer will execute, the last one (hibernate).Is there other way to use several timers?

View 1 Replies View Related

Programming :: Opencv Related - Find Out Corresponding Points Of Same Scene On Two Cameras?

May 2, 2011

I've a question regarding two camera images. Suppose I've detected 2d window coordinate of 8 markers of an object in a scene in one camera and detected window coordinates of 10 markers of the same object on another camera.

I've detected the marker. It was easy. Now how do i know which window coordinates on two cameras are the coordinates of same marker? I mean there are markers captured on both cameras and some of them are representing the same marker in both cameras. I just like to know which ones are same on both cameras. Is it possible to find that out using opencv?

View 2 Replies View Related

Programming :: Location Of - Gnu - C++ Standard Library

Jul 21, 2010

Where is the location of the header files for the c++ standard library?

I assume that they were installed by gnu g++, please correct me if i'm wrong.

I'm running ubuntu 10.04 with g++ 4.4.

I looked in /usr/lib/gcc/i486-linux-gnu/4.4/include, but this directory contains only the following:

Code:

Which doesnt seem to include the really basic things like iostream, for example.

Where can I take a look at the header files for these standard c++ libraries?

View 2 Replies View Related

Programming :: Programmatically Getting Standard File Dialog

Jul 14, 2010

Is it possible to do the following in C/C++ in Linux:Without direct linking (my program should NOT depend on Qt or GTK), display a GTK or Qt based file dialog.The behaviour should be something like this when my program runs, when you want to open a file:The program scans whether you have Qt installed. If so, it somehow manages to link itself to Qt (e.g. dynamically loading the .so file) and display its file dialog and get the path from it. If Qt wasn't found, it tries the same with GTK. If that also wasn't found, it displays a less powerful replacement dialog instead (better than nothing).

Or is there any other simple way in Linux to get a standard file dialog somehow (similar to when compiling for Windows you can very easily get its standard file dialog, no matter what version of Windows, in your code, even if your program doesn't use any other Windows GUI at all).

View 4 Replies View Related

Programming :: Reverse A String Without Using Standard Library?

Sep 22, 2010

I am making a program to reverse a string

Code:
#include<stdio.h>
int main ()
{
int i,j;

[Code].....

View 5 Replies View Related

Programming :: Awk Syntax For Calculating Average And Standard Deviation

Apr 20, 2011

I have a data in a column.

Code:

I want to calculate average and standard deviation. As first step I want to calculate average for the data than calculate (del=data - avg) for all the data.

I suppose get

Code:

For this I use AWK and the code goes like this

Code:

But I get different answers.

Code:

Why the answers are so different? since this is wrong I can not continue calculating the standard deviation.

View 6 Replies View Related

Programming :: Direct Standard Output From Find Command?

Mar 26, 2010

I'm trying to pull out sections from a bunch of files. For one file, I use:

Code:
sed '/string1/,/string2/ !d' <filename.ext >newfilename.ext
to pull out everything between two strings in the original file and put them in a new file.

[code]....

View 3 Replies View Related

Programming :: Standard For Naming Convention Of Commandline Options

Feb 22, 2011

Is there any document or specification like the Linux Standard Base for the naming convention of commandline options?

View 3 Replies View Related

Programming :: Timeout For Standard Input Using Tcsetattr Not Working?

Jan 5, 2010

The code is attached..My intention is that getchar which usually blocks,should come out after 5 seconds(VTIME).But this is not happening..can anyone tell me the mistake that I make..?

#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>

[code]...

View 3 Replies View Related

Programming :: Underscores In Standard Functions, An Example Section From Cat.c Is Included

Sep 4, 2010

From cat.c in GNU coreutils:

Code:
void
usage (int status)
{
if (status != EXIT_SUCCESS)
fprintf (stderr, _("Try `%s --help' for more information.

[Code]...

I don't remember ever seeing this in any examples I've ever seen, so I'm sure I've never seen an explanation of this.

View 1 Replies View Related

Programming :: Perl About System Command / Fails If The Standard Shell Is Dash And Not Bash?

Jun 30, 2011

I am trying to fix a perl script, and I really suck at perl. But I think this problem will be easy for people who know it.

The problem is, I have an old setup script someone wrote many years ago. It fails if the standard shell is dash and not bash. The only way I've gotten it to work is to point /bin/sh to bash. I looked thru the script and it uses "system" many places, and I think that's the problem.

I searched for it and found this link:url

My plan is to include this function:

Code:
sub system_bash {
my @args = ( "bash", "-c", shift );
system(@args);
}
Then I could simply change all calls to system into system_bash and it should work?

The parameter to the system calls is usually some variable. What if the parameter is a list already? Do I need to test for it somehow, and if it's a list, prepend "bash" and "-c" to the list? How do I do that?

In the script there are lots of places like this:

my $error = system($cmd);
if ($error) {
die/warn "some error message";
}

Shouldn't there be a return in the system_bash function?

View 8 Replies View Related

General :: Pthreads - Structure Can Be Returned With Value

May 21, 2010

I am playing around with pthreads. This program however blows up.

#include <iostream>
#include <pthread.h>
using namespace std;
struct myStruct
{
int a;
string msg;
};

void * myProc(void *arg)
{
struct myStruct* str = new struct myStruct();
str->a = 10;
str->msg ="hi";
return (void*)str;
}

int main(int argc, char **argv)
{
pthread_t mythr;
int status ;
void *retVal;
struct myStruct* m_str;
status = pthread_create(&mythr,NULL,myProc,NULL);
status = pthread_join(mythr,&retVal);
cout<<"Status is"<<status<<endl;
m_str = (struct myStruct*)m_str;
cout<<"retval is "<<m_str->a<<" "<<endl;
return 0;
}

Can a structure be returned by a thread as its return value ?

View 1 Replies View Related

General :: Pthreads - Executing Two Different Functions Simultaneously

Jul 1, 2011

In my code I want to have two different functions to be executed simultaneously (in parallel) in a single processor system. I tried to use pthreads but they happened to be executed one after another. I have heard about fork, some saying that its no longer recommended since its functions can be achieved by pthreads.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved