pthreads

Threading newbie with issue with runaway threads...

Ok, to you understand I will explain the problem: I am using a library called ClanLIB (not my choice), that library, SEEMLY (I am not certain, even reading the sourcE), creates a thread that handles sound. This thread, when the buffer is empty, tries to fetch more data, usually this cause a underrun when the data generating library is t...

Pthreads- 1 lock, 2 unlocks

If I understand correctly, then foo1() fails to unlock &private_value_. As a result, foo2()'s thread_mutex_lock does not work since foo1() never released it. What are the other consequences? int main ( ... ) foo1(); foo2(); return 0; } foo1() { pthread_mutex_lock(&private_value_); do something // no unlock! } foo2() { pthread_...

Is it possible to list mutexs which a thread holds

Firstly, I use pthread library to write multithreading c program. Threads always hung by their waited mutexs. When I use the strace utility to find a thread is in FUTEX_WAIT status, I want to know which thread hold that mutex at the time. But I don't know how could I make it. Are there any utilities could do that? Someone told me java v...

Creating threads that copy the arguments passed to them

I'm currently using boost::thread, because it very conveniently allows me to pass an arbitrary number of arguments to the thread and copies them along the way, so I don't have to worry about them being deleted before the thread launches. Is there any other library that allows this, or a way to simulate it using pthreads? I'd like to wean...

NPTL caps maximum threads at 65528?

The following code is supposed to make 100,000 threads: /* compile with: gcc -lpthread -o thread-limit thread-limit.c */ /* originally from: http://www.volano.com/linuxnotes.html */ #include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <pthread.h> #include <string.h> #define MAX_THREADS 100000 int i; void run(void) { ...

pthread_mutex_destroy blocks in infinite loop

Hello, I use POSIX threads on iPhone/iPad and when I try to destroy a mutex, pthread_mutex_destroy blocks in infinite loop. I did not find anything about this. It should return an error code... Do you know something about this? Thanks! ...

Killing a pthread waiting on a condition variable

Hi, I have a pthread waiting on a condition variable using pthread_cond_wait. It's waiting for data from a queue structure that is filled by another thread. I want to kill this thread, preferably without pthread_kill. On Linux and WinPthreads doing a pthread_cancel(); pthread_join() is enough to kill it. However, on OS X it hangs on...

Issue in pausing the posix thread for specific time interval in c

I have to call one method in seperate thread (i am using posix thread)which updates some value after every 5 second for which have written below code. void *threadEntry(void *) { while(1) { updateValue();//to update some values usleep(5000000);//pause for 5 second } } pthread_t thread1; pthread_create(&thread1,NULL,thread...

Strange C program behaviour

Hi guys, I really have a strange situation. I'm making a Linux multi-threaded C application using all the nitty-gritty memory stuff involving char* strings, and I'm stuck in a really odd position. Basically, what happens is, using POSIX threads, I'm reading and writing to a two-dimensional char array, but it has unusual errors. You hav...

Compiling errors in a program using threads

On compiling I am getting an error "undefined reference to pthread_create()" and similarly for "undefined reference to pthread_join()". What are the possible reasons? I am unable to identify them. ...

End a Process In Thread

Possible Duplicate: kill thread in pthread How can I end a process running in a thread...or in other words how can I kill a thread? ...

How to cause locks to be freed in one thread which were set by another

I have a simple thread pool written in pthreads implemented using a pool of locks so I know which threads are available. Each thread also has a condition variable it waits on so I can signal it to do work. When work comes in, I pick a thread by looking finding an available thread from the lock pool. I then set a data structure associate...

Any caveats in porting GNU Pth code for Pthreads?

I have code written using GNU Pth ( http://www.gnu.org/software/pth/ ) and I want to move to Pthreads because I want it to be cross-platform (Unix, Mac, Windows). Are there and caveats I should watch out for while going about switching from Pth to Pthreads, or is it mostly just a matter of realigning arguments and variable types? ...

a simple boss-worker model using pthreads

Hi, I'm an amateur programmer that's experimenting using pthreads, to see to what extent a multi-threaded program can lead to efficiencies in a rather long computation I'm working on. The computation runs through a std::list< string > object, popping the first element of the list off, and farming it out to a thread that computes somet...

Why this thread safe queue, creates a deadlock?

I've written my own version of thread safe queue. However, when I run this program, it hangs/deadlocks itself. Wondering, why is this locks/hangs forever. void concurrentqueue::addtoQueue(const int number) { locker currentlock(lock_for_queue); numberlist.push(number); pthread_cond_signal(&queue_availability_condition); } i...

Should pthread_mutex static initialization using PTHREAD_MUTEX_INITIALIZER avoided?

Are there any known problems of initialiazing pthread mutexes statically using PTHREAD_MUTEX_INITIALIZER and passing them directly for locking? I read in some sites that this cannot be guaranteed on all platforms and also in the help page the below note is there: Note: Mutex initialization using the PTHREAD_MUTEX_INITIALIZER does not i...

Is it possible to do static initialization of mutexes in Windows?

pthread supports static initialization of pthread_mutex_t using PTHREAD_MUTEX_INITIALIZER. Is it possible to achieve a similar static mechanism for mutex initialization using Windows mutex? ...

Is it OK to call pthread_exit from main?

When I call pthread_exit from main, the program never gets to terminate. I expected the program to finish, since I was exiting the program's only thread, but it doesn't work. It seems hung. #include <stdio.h> #include <stdlib.h> #include <pthread.h> int main(int argc, char *argv[]) { printf("-one-\n"); pthread_exit(NULL); ...

A very simple thread pool using pthreads in C++

Hello, I'm trying to understand some of the basics of using POSIX pthreads. The kind of thing I need to do (eventually) is parallelize some computations, using a thread pool model. At present I want to ensure I have a very basic sense for how the POSIX pthread model works. So I'm trying to create the simplest thread pool that's gen...

Why is this code failing under valgrind (helgrind)?

...