pthreads

Multithreading: When to Start and Exit threads

∥☆過路亽.° 提交于 2020-01-25 00:15:11
问题 I am a little further along on this exercise and was not sure if I should post an answer with my updated code, edit my original post, or ask a new question. If I am not following protocol, please advise. What I have done so far is read in the input file and assigned all the integers to an array. I then divided the total number of integers ( index ) by the number of threads ( number_of_threads ) to find the optimal numbers_per_thread . I then create a while loop to increment through all the

SIGSTOP and SIGCONT equivalent in threads

丶灬走出姿态 提交于 2020-01-24 07:25:27
问题 Is there something equivalent to SIGSTOP and SICONT for threads? Am using pthreads. Thanks An edit: I am implementing a crude form of file access syncronization among threads. So if a file is already opened by a thread, and another thread wants to open it again, I need to halt or pause the second thread at that point of its execution. When the first thread has completed its work it will check what other threads wanted to use a file it released and "wake" them up. The second thread then

SIGSTOP and SIGCONT equivalent in threads

北城以北 提交于 2020-01-24 07:25:04
问题 Is there something equivalent to SIGSTOP and SICONT for threads? Am using pthreads. Thanks An edit: I am implementing a crude form of file access syncronization among threads. So if a file is already opened by a thread, and another thread wants to open it again, I need to halt or pause the second thread at that point of its execution. When the first thread has completed its work it will check what other threads wanted to use a file it released and "wake" them up. The second thread then

sem_timedwait not supported properly on RedHat Enterprise Linux 5.3 onwards?

▼魔方 西西 提交于 2020-01-24 04:21:25
问题 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 supported. If we do the same thing on the main thread, it works as expected and we get no error from sem_timedwait. We don't see it on RHEL 5.2 or before. We've tried

Real dangers of 2+ threads writing/reading a variable

[亡魂溺海] 提交于 2020-01-24 02:59:46
问题 What are the real dangers of simultaneous read/write to a single variable? If I use one thread to write a variable and another to read the variable in a while loop and there is no danger if the variable is read while being written and an old value is used what else is a danger here? Can a simultaneous read/write cause a thread crash or what happens on the low level when an exact simultaneous read/write occurs? 回答1: If two threads access a variable without suitable synchronization, and at

Trouble with threads in a function to exec another function after X time

别来无恙 提交于 2020-01-24 01:13:11
问题 I am trying to create this function in order to exec another function after X time: void execAfter(double time, void *(*func)(void *), t_params *params); I have made an Thread encapsulation and a Time encapsulation (objects Thread and Time). What I want to do in pseudo code: Call execAfter instantiate Thread call thread->create(*funcToExec, *params, timeToWait) [inside thread, leaving execAfter] instanciate Time object wait for X time exec funcToExec delete Time object [leaving thread, back

How to share global variable across thread in php?

六眼飞鱼酱① 提交于 2020-01-23 01:11:28
问题 In multithreading the global variables or resources are shared among threads. I'm using pthread library in c #include <stdio.h> #include <pthread.h> #include <unistd.h> void *worker(void *); int ctr = 0; pthread_mutex_t lock; int main(int argc, char *argv[]) { pthread_t t[2]; int i = 0; //~ pthread_mutex_init(&lock, NULL); while(i < 2) { pthread_create(&t[i], NULL, &worker, NULL); i++; } pthread_join(t[0], NULL); pthread_join(t[1], NULL); //~ pthread_mutex_destroy(&lock); //~ pthread_join(t[1

android NDK mutex locking

被刻印的时光 ゝ 提交于 2020-01-22 23:07:56
问题 I've been porting a cross platform C++ engine to Android, and noticed that it will inexplicably (and inconsistently) block when calling pthread_mutex_lock . This engine has already been working for many years on several platforms, and the problematic code hasn't changed in years, so I doubt it's a deadlock or otherwise buggy code. It must be my port to Android.. So far there are several places in the code that block on pthread_mutex_lock. It isn't entirely reproducible either. When it hangs,

Using pthread condition variable with rwlock

不羁岁月 提交于 2020-01-22 09:44:20
问题 I'm looking for a way to use pthread rwlock structure with conditions routines in C++. I have two questions: First: How is it possible and if we can't, why ? Second: Why current POSIX pthread have not implemented this behaviour ? To understand my purpose, I explain what will be my use: I've a producer-consumer model dealing with one shared array. The consumer will cond_wait when the array is empty, but rdlock when reading some elems. The producer will wrlock when adding(+signal) or removing

Using pthread condition variable with rwlock

你说的曾经没有我的故事 提交于 2020-01-22 09:39:10
问题 I'm looking for a way to use pthread rwlock structure with conditions routines in C++. I have two questions: First: How is it possible and if we can't, why ? Second: Why current POSIX pthread have not implemented this behaviour ? To understand my purpose, I explain what will be my use: I've a producer-consumer model dealing with one shared array. The consumer will cond_wait when the array is empty, but rdlock when reading some elems. The producer will wrlock when adding(+signal) or removing