pthreads

Can pthreads only share global resources?

I'm trying to share a structure between two threads that is not a global variable. The variable itself is instantiated on the stack in the main function, then its pointer is passed as the parameter to both threads on the start up of both threads. What I'm finding is that when I change the value of a member of that structure that change...

Creating threads within the cluster

Hi, I wish to know is there any way that I can create the threads on other nodes without starting the process on the nodes. For example :- lets say I have cluster of 5 nodes I am running an application on node1. Which creates 5 threads on I want the threads not to be created in the same system but across the cluster lets say 1 node 1 t...

Reading Critical Section Data using pthreads

I have a multi-threaded application, I'm using pthreads with the pthread_mutex_lock function. The only data I need to protect is in one data structure. Is it safe if I apply the lock only when I write to the data structure? Or should I apply the lock whenever I read or write? I found a question similar to this, but it was for Windows...

Bind threads to processors

Hi, When I run my multi-threaded code, the system (linux) sometimes moves the threads from one processor to another. As I have as many threads as I have processors, it invalidates caches for no good reasons and it confuses my tracing activities. Do you know how to bind threads to processors, and why does a system would do this ? ...

On what conditions will a C++ program continue if the main thread is done?

I am debugging an issue, where there is a thread which continues to run after the main thread has exited. It is stuck in a loop where it is waiting for another thread to change a variable. I am trying to understand in what situations a process will continue running after the main thread has exited. I am using 32 bit linux g++ pthreads...

Does NSThread have a separate heap? What about pthread (on iPhone)

If I detach an NSThread will Cocoa run it in a separate memory heap or memory zone? For example, if I were to detach a thread, use malloc to create a large buffer, and then let the thread exit, would I get that memory back in some kind of automatic thread cleanup, or would it be leaked? What about if I used a POSIX thread (pthread) inst...

A question about parallelizing a task

Hello all, I have a question about parallelization: I have two datasets. Dataset1 has m rows and k columns, Dataset2 has n rows and k columns.(m > n) My program reads those datasets from files and store them in the memory. The task is to take each instance of Dataset1(let's call this query instance) and compare with all instances of Da...

pthread_cond_timedwait() help.

void wait(int timeInMs) { struct timespec timeToWait; timeToWait.tv_sec = 5; timeToWait.tv_nsec = timeInMs*1000; int rt; pthread_mutex_lock(&fakeMutex); rt = pthread_cond_timedwait(&fakeCond, &fakeMutex, &timeToWait); pthread_mutex_unlock(&fakeMutex); } I'm using this code to try to get a thread to wait ar...

Are the new and delete operators thread-safe in pthreads-w32 for visual c++?

Are the new and delete operators thread-safe in pthreads-w32 for visual c++? What things should I assume will always be thread-safe in pthreads-w32? ...

Simple C/C++ network I/O library

I have the following problem to solve. I want to make a number of requests to a number of "remote" servers (actually, a server farm we control). The connection is very simple. Send a line, and then read lines back. Because of the number of requests and the number of servers, I use pthreads, one for each request. The naive approach, ...

C Threaded Programming - Incrementing a shared variable

Hey guys...so I'm trying to brush up on my C threads and a question I've found is this: Given a global variable int x = 0; implement the function void useless(int n) which creates n threads which in a loop increase x by 1, each thread terminates when x reaches 100. I just don't have a handle on threads and need a solid example to base...

Mac/iPhone: Is there a way to get a thread identifier without using Objective-C?

Is there a way to get any kind of thread identifier of the currently running thread without resorting to Objective-C's NSThread. I'm improving our custom debug tracing system to handle multiple threads properly. For each line of trace output, I'd like to print a thread id or a thread name. Threads are instantiated in various ways, e.g....

thread level memory consumption of process

How do I get per thread based memory consumption of a process in Linux? I understand that we can use /proc/pid/task/tid/statm, but thats not helping my case. All the threads show same value and its same as PID's statm. We can do valgrind but I am not looking for any invalid read/write or leaks. Valgrind will not tell me any thread leve...

pthread was not found

I am working on pthread in C++ using visual studio 2008. I have a problem because the compiler does not find . I knew that it was embedded in C++ 2005. Do i have to install the library and add it manually or it should be installed with C++ default libraries? If i have to install it, please give me the url. Hani Almousli ...

How to sleep or pause a PThread in c on Linux

I am developing an application. In which I do multithreading. One of my worker thread display images on the widget. Another thread play sound. I want to stop/suspend/pause/sleep the threads on button click event. It is same as when we click on video player play/pause button. I am developing my application in c++ on linux platform. I use ...

cmake and libpthread

I'm ruinning on RHEL 5.1 and use gcc. How I tell cmake to add -pthread to compilation and linking? ...

Making a user space thread library with pthread, how do you properly create the first thread? (well first 2 threads)

So im making a user space thread library. lets say theres some program that uses it. in that program it starts at the main method. before any calls to create_thread, there are no threads active. then when the first thread is created, the library makes 2 threads. One for 'main' and one for the actual new thead you are making. This is th...

linux threads and fopen() fclose() fgets()

I'm looking at some legacy Linux code which uses pthreads. In one thread a file is read via fgets(). The FILE variable is a global variable shared across all threads. (Hey, I didn't write this...) In another thread every now and again the FILE is closed and reopened with another filename. For several seconds after this has happened,...

pthreads : pthread_cond_signal() from within critical section

I have the following piece of code in thread A, which blocks using pthread_cond_wait() pthread_mutex_lock(&my_lock); if ( false == testCondition ) pthread_cond_wait(&my_wait,&my_lock); pthread_mutex_unlock(&my_lock); I have the following piece of code in thread B, which signals thread A pthread_mutex_lock(&my_lock...

pthreads, setjmp, longjmp. How can you tell when a function is finished running?

I am writing a user space thread library. I have a struct that manages each thread. My threads are very simple, they take a function ptr and its arguments, and just run that function one time. Each thread has a jmp_buf and I use setjmp and longjmp to switch between threads. One thing I cant figure out is how to tell when this function i...