pthreads

Equivalent of "pthread_rwlock_timedrdlock()" and "pthread_rwlock_timedwrlock()" in MSVC/Windows

What is the equivalent of following POSIX timed Reader/Writer locks in windows(MSVC)? pthread_rwlock_timedrdlock() pthread_rwlock_timedwrlock() ...

Is PThread a good choice for multi-platorm C/C++ multi-threading program?

Been doing mostly Java and smattering of .NET for last five years and haven't written any significant C or C++ during that time. So have been away from that scene for a while. If I want to write a C or C++ program today that does some multi-threading and is source code portable across Windows, Mac OS X, and Linux/Unix - is PThread a goo...

pthread conditional variable

I'm implementing a thread with a task queue. As soon as as the first task is added to the queue the thread starts running it. Should I use pthread condition variable to wake up the thread or there is more appropriate mechanism? If I call pthread_cond_signal() when the other thread is not blocked by pthread_cond_wait() but rather doing...

Where does this deadlock hide?

Hi, I'm actually writing an MPI program. This is a basic client / server pattern. The server have a set of work to compute. The clients get subsets of this big set. Each client use several threads to compute the subset. I must be sure all the threads finished before requesting another subset to the server. The client is split into seve...

Problem with thread-safe queue?

I'm trying to write a thread-safe queue using pthreads in c++. My program works 93% of the time. The other 7% of the time it other spits out garbage, OR seems to fall asleep. I'm wondering if there is some flaw in my queue where a context-switch would break it? // thread-safe queue // inspired by http://msmvps.com/blogs/vandooren/archiv...

Static linking with pthreads & stdc++?

Is it possible to statically link my program with libpthreads and libstdc++ on Linux? ...

How to create a shared object that is statically linked with pthreads and libstdc++ on Linux/gcc?

How to create a shared object that is statically linked with pthreads and libstdc++ on Linux/gcc? ...

C : how pthread dataspecific works?

I'm not sure about how pthread dataspecific works : considering the next code (found on the web), does this means i can create for example 5 threads in the main, have a call to func in only some of them (let's say 2) those threads would have the data 'key' set to something (ptr = malloc(OBJECT_SIZE) ) and the other threads would have the...

How do I get a thread ID from an arbitrary pthread_t?

I have a pthread_t, and I'd like to change its CPU affinity. The problem is that I'm using glibc 2.3.2, which doesn't have pthread_setaffinity_np(). That's OK, though, because pthread_setaffinity_np() is itself a wrapper of sched_setaffinity(), which can be called by passing a thread ID instead of a process ID to set the affinity for an ...

pthreads - how to parallelize a job

I need to parallelize a simple password cracker, for using it on a n-processor system. My idea is to create n threads and to feed them more and more job as they finish. What is the best way to know when a thread has finished? A mutex? Isn't expensive checking this mutex constantly while other threads are running? ...

Deadlocks with pthreads and CreateThread

I'm using pthreads in a Windows application. I noticed my program was deadlocking--a quick inspection showed that the following had occurred: Thread 1 spawned Thread 2. Thread 2 spawned Thread 3. Thread 2 waited on a mutex from Thread 3, which wasn't unlocking. So, I went to debug in gdb and got the following when backtracing the th...

C : pthread dataspecific destructor called only once

From pthread_key_create manpage : An optional destructor function may be associated with each key value. At thread exit, if a key value has a non-NULL destructor pointer, and the thread has a non-NULL value associated with the key, the function pointed to is called with the current associated value as its sole argume...

How to keep process from exiting when a pthread exits?

I am writing a server program in C wherein every time a client connects, I create a new pthread to handle the client's requests. When all of the threads exit, however, then my program exits, as though a call to exit() has been made. This is a problem - how can I overcome it? Lets say the server is running, and 2 clients connect. Once t...

Linux thread resource leak?

In one of the multithreaded Linux application, the application quits without deleting the thread. Will this cause any thread resource leakage. If this application is launched many times during the course of the day, will the system crash? ...

calling a callback from a thread using function pointers

Hello, c program compiler gcc I have 3 files. main.c stop_watch.h and stop_watch.c This program does work. I call start_stopwatch. And it will callback in main.c timeout_cb() after the time has expired. I also run this in a seperate thread, as I don't want to block in main, as I will have other code I need to run. 1) The seconds in g...

How do I read/write a shared variable with pthreads?

I have two threads, using C pthreads on linux. One of them writes data and the other is reading it. I'm using a variable to allow the read thread when is allowed to read and the write one when is allowed. So the mutex applies to this boolean variable called "newData". My question is: do I need to lock/unlock the mutex around the accesses...

pthread callbacks interupt user input

I have written my own stop_watch module. That will create a thread and go to sleep for a period of seconds. Once the seconds have expired it will call a callback function in the main.c and inform the user the time has expired. This is so that the user will only have 3 seconds to enter a digit and they will have to enter 5 digits. If th...

What can make a program run slower when using more threads?

This question is about the same program I previously asked about. To recap, I have a program with a loop structure like this: for (int i1 = 0; i1 < N; i1++) for (int i2 = 0; i2 < N; i2++) for (int i3 = 0; i3 < N; i3++) for (int i4 = 0; i4 < N; i4++) histogram[bin_index(i1, i2, i3, i4)] += 1; bin_index is a complete...

Why would pthread_create() fail with only 2 threads active?

I'm having some trouble in my first foray into threads in C. I'm trying (for now) to write a very simple server program that accepts a socket connection and starts a new thread to process it. It seems to work fine except that it will only create about 300 threads (303, sometimes 304) before pthread_create() fails with the EAGAIN code, wh...

pthread_cancel behaves differently on arm and ppc?

I'm currently working on a multi-threaded application that would be deployed on arm and ppc architecture. I'm having some problem with pthread_cancel on arm. pthread_cancel on arm doesn't behave the same with ppc. The thread gets cancelled but the destructor for the thread's local variable isn't being called on arm. I also tried explic...