pthreads

Still Reachable Leak detected by Valgrind

All the functions mentioned in this block are library functions. How can I rectify this memory leak? It is listed under the "Still reachable" category. (There are 4 more, which are very similar, but of varying sizes) 630 bytes in 1 blocks are still reachable in loss record 5 of 5 at 0x4004F1B: calloc (vg_replace_malloc.c:418) ...

Maximum number of threads

I have a program which accepts 2 N-digit numbers, multiplies them using threads & prints the output. The number of threads created here are 2 * N - 1. whenever I run the program for N > 151, the program gives me a segmentation fault. Is there a cap on maximum number of threads a process can get from the thread pool? If so, could thi...

pthread_exit vs. return

I have a joinable pthread runner function defined as below: void *sumOfProducts(void *param) { ... pthread_exit(0); } This thread is supposed to join the main thread. Whenever I ran my program through Valgrind I would get the following leaks: LEAK SUMMARY: definitely lost: 0 bytes in 0 blocks indirectly lost: 0 bytes in 0 bloc...

concurrent threads in C programming

I have encountered a problem while implementing wait and signal conditions on multiple threads. A thread needs to lock a mutex and wait on a condition variable until some other thread signals it. In the meanwhile, another thread locks the same mutex and waits on the same condition variable. Now, the thread which is running concurrently ...

how number of thread should be accepted via command line using pthread?

I am writting an application that has multiple threads in Linux environment using C or python. I am using pthread for that. But How number of threads should be accepted via command line. ...

How to solve the DLL function call problem

Hi, i have couple of query's with respect to DLL, 1)If i load the DLL in run time, i guess DLL will be in separate thread right? 2)If i call a function present in DLL, and that function takes much time to return the value then how can i make my application thread to wait till the DLL's function return value. How can i solve the seco...

Question about zombie processess and threads

Hi, i had these questions in my mind since i was reading some new topics on processes and threads. I would be glad if somebody could help me out. 1) What happens if a thread is marked uncancelable, and then the process is killed inside of the critical section? 2) Do we have a main thread for the program that is known to the operating s...

Current right way to do thread programming in Linux

I know that the implementation of threads in the Linux kernel and libc went through big changes in the past. What is the best way to use threads today from C programs? (I don't even know if there is more than one API that I can use -- I just know pthreads) I don't care too much about old kernels and libc versions, but I do care about ma...

Segfault immediately after pthread creation

Hello all, I have a producer/consumer concurrency problem that I'm working on. The problem is that I'm getting a segfault thrown immediately after trying to create my first thread. Relevant code: customer is a struct declared as: struct pr2_customer { pthread_t customer_id; }; typedef struct pr2_customer customer; customers i...

Tutorial on Using OpenSSL with pthreads

OpenSSL documents state that it can safely be used in multi-threaded applications provided that at least two callback functions are set, locking_function and threadid_func.... I've written programs which use OpenSSL API. Moreover, I know how to use pthreads. However, the OpenSSL documents are written in the form of a manual, and I can't...

How much overhead is there when creating a thread?

Hey all, I just reviewed some really terrible code - code that sends messages on a serial port by creating a new thread to package and assemble the message in a new thread for every single message sent. Yes, for every message a pthread is created, bits are properly set up, then the thread terminates. I haven't a clue why anyone would do...

Using Thread for Taking input in one of them and Displaying output in the other one

I am making a chat application for my homework which runs within a Linux Terminal. So, I need to take from the user some input and display the output from all the users as well in a well organized manner. So, I made two threads. One thread have a cin command and the other thread is having a display function which basically uses printf to...

C Pthreads mutex values?

I am writing a program with a few critical sections. The thing is I need to check the value of a mutex in an if statement. I would like to do something like this: if pthread_mutex(&mutex) == 0 // locked // Do something else if pthread_mutex(&mutex) == 1 // unlocked // Do something else Is this possible? ...

Issue with threads: value stored in heap

Hello, I have an issue with threads. I am defining a global variable, a char * that I initialize to NULL, and a mutex. pthread_mutex_t mutex; char *minURLTime; minURLTime = NULL; Then I initialize my mutex: pthread_mutex_init(&mutex, NULL); I then create a new thread: void *status; pthread_t t; pthread_create(&t, NULL, executeTh...

Pthreads vs. OpenMP

I'm creating a multi-threaded application in C using Linux. I'm unsure whether I should use the POSIX thread API or the OpenMP API. What are the pros & cons of using either? Edit: Could someone clarify whether both APIs create kernel-level or user-level threads? ...

How can a thread function access variables of the parent thread

I read that threads share the memory address space of it's parent thread. If that is true , why can't a thread function access a local variable belonging to it's parent thread ? void* PrintVar(void* arg){ printf( "%d\n", a); } int main(int argc, char*argv[]) { int a; a = 10; pthread_t thr; pthread_create( &thr, NULL, Pri...

Debugging tools for Multithreaded Apps

What free tools can I use to debug multithreaded programs created using the pthread library in Linux? (Besides pen & paper, of course...) The usual way of printing debug messages isn't working out very well. ...

pthread_create from a child process

I'm sure I'm missing something basic, but I'm writing a program that fork()s several child processes, each of which create several pthreads. It seems that the pthread_create call never works from a child process. Here is sample code to explain what I mean: #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <pthread.h> ...

versatile pthread based multithread utility library

Hi folks. I don't want to reinvent the wheel, and what I'm looking for most likely already exist in the FOSS world. I'm looking for a pthread bases utility library that implements often used primitives to do communication between threads. My main need is some kind of blocking queue for fixed size messages and the ability to wait for ...

Starting pthreads simultaneously

What are the different ways of ensuring that a bunch of pthreads all start at the same time? I could find only one way, ie. initializing a barrier in the main thread, then waiting on it in the newly created pthreads. ...