pthreads

Does pthreads support a method for querying the "lock count" of a recursive mutex?

Does pthreads support any method that allows you to query the number of times a recursive mutex has been locked? ...

thread termination issue (c programming)

I'm working on an application for Linux in C which uses multiple threads. The threads which are spawned by the main function do most of the work, and therefore usually finish last. I'm seeing some strange behavior, and I believe it's due to the main thread terminating before the spawned threads have a chance to finish their jobs. Here's ...

passing a pointer to a structure as an argument to a thread cancellation cleanup handler

I'm having trouble passing a pointer to a structure as an argument to a thread cancellation cleanup handler. Here's some sample code that blows up when it hits the compiler. Any idea what I'm doing wrong? #include <pthread.h> typedef struct struct_def { /* data */ } struct_def; struct_def *ptr_to_struct_def; void * thread_functi...

Wait for a detached thread to finish in C++

How can I wait for a detached thread to finish in C++? I don't care about an exit status, I just want to know whether or not the thread has finished. I'm trying to provide a synchronous wrapper around an asynchronous thirdarty tool. The problem is a weird race condition crash involving a callback. The progression is: I call the thi...

example of thread specific data in C

Does anybody know of (or can post) an example of the use of thread-specific data? I'm looking for something that's clearly explained and easy to understand. I've got a global char * variable that I'm wanting to share between a couple threads, and I'm thinking this is what the thread specific data mechanism in C is for, am I right? I'm a...

What is the difference between Go's multithreading and pthread or Java Threads?

What is the difference between Go's multithreading approach and other approaches, such as pthread, boost::thread or Java Threads? ...

Pthreads question

How to check if a thread is terminated? In my case, I have my_pthread[5] and I want to check if any in 5 threads has finished its job (terminated???I'm not sure) then I can give them another work to do. If I use pthread_join(), then it has to be pthread_join(my_pthread[0]); ... pthread_join(my_pthread[4]); What if thread[3] finishes...

How to print pthread_t

Searched, but don't come across a satisfying answer. I know there's no a portable way to print a pthread_t. How do you do it in your app? UDP: Actually I don't need pthread_t, but some small numeric id, identifying in debug message different threads. On my system (64 bit RHEL 5.3) it's defined as unsigned long int, so it's big n...

In which include file EPERM (returned by pthread_mutex_unlock) error code is declared?

Can anyone give me the right direction for this, as I am not able to find the declaration of EPERM in either pthread.h or errno.h (on openSUSE Linux). I found this in asm-generic/errno-base.h but is this the right one? Why its not in errno.h? Thanks ...

How do you run several pthreads, in C, and detect the first to terminate?

How do you run several pthreads, in C, and detect the first to terminate? I'm thinking there has got to be an interface similar to select() for sockets to do this with threads. Thanks, Chenz ...

Pthreads C/C++ compilation problem

Hello, I'm getting error "undefined reference to `pthread_attr_init'", even though that should be in pthread.h. This is in a UNIX environment that should be set up for Pthreads. Also, is a void* a good way to point to the current matrix? Here's my code, any ideas? #include <cstdlib> #include <iostream> #include <sstream> #include <strin...

Handling segfault signal SIGSEGV need to determine the cause of segfault using siginfo_t

Im making a wrapper for the pthread library that allows each thread to have its own set of non-shared memory. Right now the way c is set up if any thread tries to rwe another threads data, the program segfaults. This is fine, I can catch it with a sighandler and call pthread_exit() and continue on with the program. But not every segfaul...

Race between virtual function and pthread_create

When I try to create a class instance with a virtual method and pass it to pthread_create, I get a race condition, causing the caller to sometimes call the base method instead of the derived method like it should. After googling pthread vtable race, I found out this is fairly well-known behavior. My question is, what's a good way to ge...

sem_timedwait not supported properly on RedHat Enterprise Linux 5.3 onwards?

Hi, We're seeing odd behaviour on RedHat Enterprise Linux systems with pthreads sem_timedwait. It's only occurring with versions 5.3 onwards. When we create the semaphore on a background thread with sem_init, no error is returned. When we do sem_timedwait, we get an immediate return with errno = 38 (ENOSYS) indicating it's not suppor...

C - massive # of posix threads spinning out of control and no longer creating new ones

I have an assignment in class that requires us to use POSIX threads and create n*(n-1)/2 of them to process a dataset of n elements. You can think of it as basically the classical "handshake" in probability. I know that for a large data set it's going to make the application CPU-bound and eventually it will spend so much time context s...

gdb backtrace and pthread_cond_wait()

This is on a Redhat EL5 machine w/ a 2.6.18-164.2.1.el5 x86_64 kernel using gcc 4.1.2 and gdb 7.0. When I run my application with gdb and break in while it's running, several of my threads show the following call stack when I do a backtrace: #0 0x000000000051d7da in pthread_cond_wait () #1 0x0000000100000000 in ?? () #2 0x0000000000...

NPTL Default Stack Size Problem

Hello, I am developing a multithread modular application using C programming language and NPTL 2.6. For each plugin, a POSIX thread is created. The problem is each thread has its own stack area, since default stack size depends on user's choice, this may results in huge memory consumption in some cases. To prevent unnecessary memory us...

Upgradeable read/write lock Win32

I am in search of an upgradeable read write lock for win32 with the behaviour of pthreads rwlock, where a read lock can be up- and downgraded. What I want: pthread_rwlock_rdlock( &lock ); ...read... if( some condition ) { pthread_rwlock_wrlock( &lock ); ...write... pthread_rwlock_unlock( &lock ); } ...read... pthread_rwlock...

how to synchronize a varied number of threads?

Hi, Could someone please help me with synchronizing varied number of threads? The problem is when the number of threads can vary from one to 9 and when for instance two clients are connected to server, the communication should be synchronized in this form : client1, client2, client1, client2 ... until the communication is over. I tried ...

Pthreads problem and a few questions...

#include<pthread.h> #include<stdio.h> #include<stdlib.h> #include<time.h> #define NUM_THREADS 8 char *messages[NUM_THREADS]; struct thread_data { int thread_id; int sum; char *message; }; struct thread_data thread_data_array[NUM_THREADS]; void *PrintHello(void *threadarg) { int taskid, sum; char *hello_msg; struct ...