I have a queue structure that is being used by several pthreads. The threads are supposed to dequeue from the queue if it's not empty and then do their business.
I initially had this set up as a while loop where the threads checked whether the queue was empty using a mutex_lock. Unfortunately this slowed my program down to a crawl.
I t...
I have 4 threads, and I am trying to set thread 1 to run on CPU 1, thread 2 on CPU 2, etc.
However, when I run my code below, the affinity masks are returning the correct values, but when I do a sched_getcpu() on the threads, they all return that they are running on CPU 4.
Anybody know what my problem here is?
Thanks in advance!
#defi...
I've managed to get my pthreads program sort of working. Basically I am trying to manually set the affinity of 4 threads such that thread 1 runs on CPU 1, thread 2 runs on CPU 2, thread 3 runs on CPU 3, and thread 4 runs on CPU 4.
After compiling, my code works for a few threads but not others (seems like thread 1 never works) but runni...
hi everyone,
my question is somewhat conceptual, how is parent process' data shared with child process created by a fork() call or with a thread created by pthread_create()
for example, are global variables directly passed into child process and if so, does modification on that variable made by child process effect value of it in pare...
I've been trying to understand the intricacies of how POSIX threads and POSIX signals interact. In particular, I'm interested in:
What's the best way to control which thread a signal is delivered to (assuming it isn't fatal in the first place)?
What is the best way to tell another thread (that might actually be busy) that the signal ha...
The usual pattern for a singleton class is something like
static Foo &getInst()
{
static Foo *inst = NULL;
if(inst == NULL)
inst = new Foo(...);
return *inst;
}
However, it's my understanding that this solution is not thread-safe, since 1) Foo's constructor might be called more than once (which may or may not matter) and...
I have this piece of code that is giving me trouble.
I know all the threads are reading the same struct. But I have no idea how to fix this.
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int a,b;
} s_param;
void *
threadfunc(void *parm)
{
s_param *param2 = parm;
printf("ID:%d and v:%d\n",param2->a...
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#define NUM_THREADS 4
#define TCOUNT 5
#define COUNT_LIMIT 13
int done = 0;
int count = 0;
int thread_ids[4] = {0,1,2,3};
int thread_runtime[4] = {0,5,4,1};
pthread_mutex_t count_mutex;
pthread_cond_t count_threshold_cv;
void *inc_count(void *t)
{
...
Hi,
which compiling a multithreaded program we use gcc like below:
gcc -lpthread -D_REENTRANT -o someprogram someprogram.c
what exactly is the flag -D_REENTRANT doing over here?
...
I have a small daemon that I'm writing in C and I need a way to get the current CPU time on a thread. Linux apparently supplies a number of ways to go about doing this, clock_gettime(CLOCK_THREAD_CPUTIME_ID, ...), pthread_getcpuclockid(), getrusage(RUSAGE_THREAD, ...) but none of these seem to be supported under OpenSolaris 2009.06.
Is ...
We have a C++ shared library that uses ZeroC's Ice library for RPC and unless we shut down Ice's runtime, we've observed child processes hanging on random mutexes. The Ice runtime starts threads, has many internal mutexes and keeps open file descriptors to servers.
Additionally, we have a few of mutexes of our own to protect our intern...
Can I create kernel-level thread using pthread_create() function with PTHREAD_SCOPE_PROCESS option in Linux kernel 2.6?
And how can I know which thread-level is my thread on? Are there any function for that?
...
i.e.
open a listening socket in parent process
call epoll_wait(listening_socket) in child1,child2,child3....
call accept in each child if there is connection request
...
I have program that runs fast enough. I want to see the number of threads created by the program.
ldd test
shows use of library pthread. but how to find out number of threads created by the program. I only have command line access to the PC on which the program is run.
The platform is linux.
...
Hi,
I have a program which uses two threads. I have put the break point in both the threads. While running the program under gdb I want to switch between the threads and make them run.
(thread t1 is active and running and thread t2; when paused on the breakpoint. I want to stop T1 running and run the T2).
Is there any way that I can sc...
Hello, i have the following code:
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#define NUM_THREADS 100
struct thread_param {
char *f1;
char *f2;
int x;
};
void *thread_function(void *arg){
printf("%d\n", ((struct thread_param*)arg)->x);
}
int main(int argc, char *argvs[]){
int i, thread_cr_res = 0,...
Hello, I wanted to write a program that test if two files are duplicates (have exactly the same content). First I test if the files have the same sizes, and if they have i start to compare their contents.
My first idea, was to "split" the files into fixed size blocks, then start a thread for every block, fseek to startup character of ev...
Hello, I'm trying to port a code that relies on SIGCONT to stop certain threads of an application. With current linux nptl implementation seems one can't rely on that in 2.6.x kernels. I'm trying to devise a method to stop other threads. Currently I can only think on mutexes and condition variables. Any hints is appreciated.
...
Hi all, I'm working on a graphical application which looks something like this:
while (Simulator.simulating)
{
Simulator.update();
InputManager.processInput();
VideoManager.draw();
}
I do this several times a second, and in the vast majority of cases my computation will be taking up 90 - 99% of my processing time. What I w...
I am using pthread.h in a *.cc file. when I try to use pthread_exit(0); or pthread_join(mythrds[yy],NULL); it says : .cc:(.text+0x3e): undefined reference to `pthread_exit'
when complied very similar code in a *.c file with gcc it work perfect. How Can I use pthread's in c++.. (I also added -lpthread)
..
void *myThreads ( void *ptr )
...