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? ...
Does pthreads support any method that allows you to query the number of times a recursive mutex has been locked? ...
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 ...
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...
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...
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 approach and other approaches, such as pthread, boost::thread or Java Threads? ...
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...
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...
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? I'm thinking there has got to be an interface similar to select() for sockets to do this with threads. Thanks, Chenz ...
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...
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...
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...
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...
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...
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...
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...
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...
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 ...
#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 ...