Hello,
I have a bit of code which used pthread_cond_wait which looks like this:
struct timespec ts;
clock_getttime(CLOCK_REALTIME, &timS);
ts.tv_sec += delay;
pthread_mutex_lock(&a_mutex);
pthread_cond_timedwait(&thread_cond, &a_mutex,&timS);
pthread_mutex_unlock(&a_mutex);
But I get a linker error on compilation,
undefine...
With a pthread_cond_t we have to associate a mutex, When signalling the condition I've seen code such as
pthread_mutex_lock(&mutex);
//code that makes condition true
pthread_cond_broadcast(&cond);
pthread_mutex_unlock(&mutex);
and
pthread_mutex_lock(&mutex);
//code that makes condition true
pthread_mutex_unlock(&mutex);
pthread_...
I'm encountering the following error at unpredictable times in a linux-based (arm) communications application:
pthread_mutex_lock.c:82: __pthread_mutex_lock: Assertion `mutex->__data.__owner == 0' failed.
Google turns up a lot of references to that error, but little information that seems relevant to my situation. I was wondering if ...
Hi all,
I am porting my application to windows from Linux. I am fairly new to the fine-art of porting application across platforms. As far as I know, Windows does not natively support POSIX threads implementation. Is this true? I have heard about some implementation of pthreads for windows (a wrapper or something), would it be better to ...
I have no idea why this dosent work
#include <iostream>
#include <pthread.h>
using namespace std;
void *print_message(){
cout << "Threading\n";
}
int main() {
pthread_t t1;
pthread_create(&t1, NULL, &print_message, NULL);
cout << "Hello";
return 0;
}
Error: [Description, Resource, Path, Location, Type] init...
Is there a way to get the nr of processing units like cpus or cores in a system? I am going to write an app with pthreads so if there is a posix call that would be great. I know about reading from /proc/cpuinfo but that is not so portable. Is there another more portable way?
...
I'm learning pthread and wait conditions. As far as I can tell a typical waiting thread is like this:
pthread_mutex_lock(&m);
while(!condition)
pthread_cond_wait(&cond, &m);
// Thread stuff here
pthread_mutex_unlock(&m);
What I can't understand is why the line while(!condition) is necessary even if I use pthread_cond_signal() to ...
I am writing a program that uses shared memory and semaphores for ipc. There is one main server process that creates the shared memory and semaphores. Any number of client processes can attach to the shared memory and read and write to it when allowed. The semaphores provide the blocking mechanism to control reads and writes. Everything ...
Lets say i have a class such as
class c{...
void *print(void *){ cout << "Hello"; }
}
And then i have a vector of c
vector<c> classes; pthread_t t1;
classes.push_back(c());
classes.push_back(c());
Now i want to create a thread on c.print();
And the Following is Giving me problem
pthread_create(&t1, NULL, &c[0].print, NULL);
...
I have the following Windows code that spawns two threads then waits until they have both completed:
hThreads[0] = _beginthread(&do_a, 0, p_args_a);
hThreads[1] = _beginthread(&do_b, 0, p_args_b);
WaitForMultipleObjects(2, hThreads, TRUE, INFINITE);
I am now porting the same code to use pthreads but am unsure how to do the equivalent ...
What is the concept of implementing Thread-pool (in C with help from pthreads)?
how can a thread be assigned to execute from the thread pool ?
...
I was told that the iPhone does not support multitasking and multithreading. This did not make sense to me, so I tested on the simulator: pthreads works, fork() doesn't.
This result does make sense to me, but now I'm not sure: will the pthread library also work on the real device?
Thanks.
...
I'm linking a C++ source with a C source and a C++ source. I create a thread with pthread, a cancellation point and then I call pthread_exit either through the C or the C++ source file.
If the pthread_exit call comes from the C source, the cancellation handler does not fire! What may be the reason for this?
b.cc:
#include <cstdio>
#in...
I am working on a multi-threaded C application using pthreads. I have one thread which writes to a a database (the database library is only safe to be used in a single thread), and several threads which are gathering data, processing it, and then need to send the results to the database thread for storage. I've seen in mentioned that it ...
I have some confusion with POSIX Threads, I want to know if my understanding of Pthreads is proper,
According to me its a layer above the native layer which helps in dealing with multithreading.
It provides a common syntax, which helps while porting from one OS to other.
It internally takes care of the various OS specific constructs.
...
Assuming I have a C program with 3 POSIX threads, sharing a global variable, mutex, and condition variable, two of which are executing the following psuedocode:
...process data...
pthread_mutex_lock( &mutex );
variable = data_ptr;
pthread_cond_signal( &cond );
pthread_mutex_unlock( &mutex );
And the third running:
while(1) {
whil...
Is there a way to change UID/GID only of one thread in a multithreaded process?
The reason for this is writing a file-serving application - the ACL's and quota are not enforced unless the uid/gid of the caller is set to the correct user, new files/directories are not created with correct uid/gid etc.
The network applications can usual...
Starting with pthreads, I cannot understand what is the business with pthread_key_t and pthread_once_t?
Would someone explain in simple terms with examples, if possible?
thanks
...
I have some threaded code using PThreads on Linux that, I suspect, is suffering from excessive lock contention. What tools are available for me to measure this?
Solaris has DTrace and plockstat. Is there something similar on Linux? (I know about a recent DTrace port for Linux but it doesn't seem to be ready for prime time yet.)
...
I'm trying to make a C++ API (for Linux and Solaris) thread-safe, so that its functions can be called from different threads without breaking internal data structures. In my current approach I'm using pthread mutexes to protect all accesses to member variables. This means that a simple getter function now locks and unlocks a mutex, and I...