pthreads

Returning values from pthread asynchronously at regular intervals

Hi, The main() function creates a thread that is supposed to live until the user wishes to exit the program. The thread needs to return values to the main functions at periodic intervals. I tried doing something like this, but hasn't worked well - std::queue<std::string> q; void start_thread(int num) { std::string str; //Do some pro...

electric-fence with pthread

I'm working on a multithreaded (pthread based) project. The project uses a library that I'm writing. In order to check it I linked it with -lefence and it gave me SIGSEGV. After a lot of time spent in figuring out what's wrong, I finally decided to search the error on the library, even if it's functionality is extremely simple. As test...

Bus error on OSX - pthreads

Hi, am trying to get my head around the following: Have a small program am trying to port to OSX(intel) which calls function doWork() via pthread_create, in the function, I start by creating an array of long like such: long myarray[DIMENSION] on OSX, for the following values of DIMENSION, I get the following: 0->65434 = fine 6543...

pthreads in C - pthread_exit

For some reason I thought that calling pthread_exit(NULL) at the end of a main function would guarantee that all running threads (at least created in the main function) would finish running before main could exit. However when I run this code below without calling the two pthread_join functions (at the end of main) explicitly I get a seg...

Problem with the timmings of a program that uses 1-8 threads on a server that has 4 Dual Core Cpu's?

Hello, I am runig a program on a server at my university that has 4 Dual-Core AMD Opteron(tm) Processor 2210 HE and the O.S. is Linux version 2.6.27.25-78.2.56.fc9.x86_64. My program implements Conways Game of Life and it runs using pthreads and openmp. I timed the parrallel part of the program using the getimeofday() function using 1-8...

Preferred pthread settings for receive->process->send kind of applications ?

we are having an old application written in C++ which is receiving requests from different clients over socket(there is a thread for each connected client). There x number of worker threads, incoming requests are being distributed among worker threads.Worker threads are processing the requests and again distributing the processed data am...

Two mutex condvar

If I have 2 mutexes locked, and I have a condvar for each one, is there an easy way to wait for either condvar to fire? I want to leave holding both locks again, and with (at least) one of the condvars having been signaled. ...

AIX pthread_create failure with EAGAIN. WLM class limits on threads?

The AIX man page for pthread_create documents the following reasons for an EAGAIN pthread_create failure: EAGAIN If WLM is running, the limit on the number of threads in the class is reached. EAGAIN The limit on the number of threads per process has been reached. I'm seeing this in test code that...

volatile and multithreading?

In the following code: #include <pthread.h> #include <unistd.h> #include <stdio.h> pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; int ready = 0; wait() { int i; do { usleep(1000); pthead_mutex_lock(&mutex); i = ready; pthread_mutex_unlock(&mutex); } while (i == 0); printf("Fin...

Do you need to reset a pthread condition variable after use?

Hi all. Just getting started with pthreads & condition variables. I have an object that has a couple of mutexes and a condition variable as members. I initialize them all in the constructor. After using the condition variable to signal waiting threads, do I need to reset it somehow if the object's state changes and the condition is n...

pthreads : allowed number of threads

Hi, I have been working now for few days on a small C program which uses pthreads. I spent more or less all yesterday looking for a deadlock bug, but now I have found out that the problem is not really a deadlock bug. The following piece of code has exactly the same problem. #include <stdlib.h> #include <pthread.h> #include <semaphore....

Pthread lost signals / slow conditions?

Hello, I'm writing a simple threadpool for some small jobs (100 to 700 microseconds). I'm working only with two threads (because there are only two jobs and the processor has only two cores). My problem is that most of the time both jobs are executed by the same thread. The problem does not occur with bigger jobs (some milliseconds). T...

Need help with ncurses cursor and threads

I am using ncurses to write a text-based client in C. The main loop of the program simply blocks until a keypress is detected and then handles it and continues to wait for another keypress. I have a single thread I launch (posted below) that blocks (using select) waiting for input from the server and when it receives it adds it to the c...

In pthread, how to reliably pass signal to another thread?

I'm trying to write a simple thread pool program in pthread. However, it seems that pthread_cond_signal doesn't block, which creates a problem. For example, let's say I have a "producer-consumer" program: pthread_cond_t my_cond = PTHREAD_COND_INITIALIZER; pthread_mutex_t my_cond_m = PTHREAD_MUTEX_INITIALIZER; void * liberator(void * ar...

OpenSSL and multi-threads

I've been reading about the requirement that if OpenSSL is used in a multi-threaded application, you have to register a thread identification function (and also a mutex creation function) with OpenSSL. On Linux, according to the example provided by OpenSSL, a thread is normally identified by registering a function like this: static uns...

pthread_create ENOMEM around 32000 threads

The process running get stuck around 32 000 (± 5%) ~# cat /proc/sys/kernel/threads-max 127862 ~# ulimit -s stack size (kbytes, -s) 2048 free memory available : 3,5 Go Further more when I try basic command while the process is stuck like "top", I get the bash message : can't fork, not enough memory. Even if there is stil...

Max number of socket on Linux

It seems that the server is limited at ~32720 sockets... I have tried every known variable change to raise up this limit. But the server stay limited at 32720 opened socket, even if there is still 4Go of free memory and 80% of idle cpu... Here's the configuration ~# ulimit -a core file size (blocks, -c) 0 data seg size ...

When to use pthread_cancel and not pthread_kill

When does one use pthread_cancell and not pthread_kill? ...

will Ptheard kill free dynamic memory allocated in the thread function?

Hi All, I have a thread function which allocates memory using malloc(). I kill the thread using pthread_kill without freeing the dynamically allocated memory.Will it be freed automatically once i call pthread_kill or there will be a leak? ...

Pinning pthreads memory and cpu

I'm working on a project in C that requires threads running on separate CPUs than the initial process. I am using the pthread library to create these threads. I use sched_setaffinity to pin the main process to a cpu. Can I do the same for each thread to pin them to separate CPUs? I am also pinning the memory of the main process. Will a ...