pthreads

Linux: How can I find the thread which holds a particular lock?

跟風遠走 提交于 2020-01-14 10:15:11
问题 I have a multi-threads program which is running on Linux, sometimes if I run gstack against it, there is a thread was waiting for a lock for a long time(say, 2-3 minutes), Thread 2 (Thread 0x5e502b90 (LWP 19853)): 0 0x40000410 in __kernel_vsyscall () 1 0x400157b9 in __lll_lock_wait () from /lib/i686/nosegneg/libpthread.so.0 2 0x40010e1d in _L_lock_981 () from /lib/i686/nosegneg/libpthread.so.0 3 0x40010d3b in pthread_mutex_lock () from /lib/i686/nosegneg/libpthread.so.0 ... I checked the rest

Convert a process based program into a thread based version?

断了今生、忘了曾经 提交于 2020-01-14 07:01:06
问题 I currently have this program which spawns an arbitrary number of child processes and I'm interested in having it implement threads instead of processes. I'm having trouble understanding how to convert from what I have, here is the code which uses processes: #include<stdio.h> #include<stdlib.h> #include<unistd.h> void childprocess(int num); int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "Usage: %s num-procs\n", argv[0]); exit(EXIT_FAILURE); } int counter; pid_t pid =

how to enable pthreads on MAMP

≡放荡痞女 提交于 2020-01-14 03:50:42
问题 I'm using a Mac with OS X Mavericks, and running php scripts within MAMP. Some of the php scripts I'm running require the use of pthreads. Can anyone provide step-by-step instructions on installing or enabling pthreads on a Mac? I have Googled extensively and have found little-to-no documentation on this. All I have found is that I may or may not have to recompile php from source, or maybe just add a couple flags to php.ini, or maybe I can just use pecl, etc. In terminal, I tried pecl install

pthread scheduling methods?

流过昼夜 提交于 2020-01-13 18:11:28
问题 With no explicit scheduling, pthreads are scheduled to run by the kernel in a random manner. Are there any scheduling methods defined in the pthread library for the same such as priorities? 回答1: The priority of a thread is specified as a delta which is added to the priority of the process. Changing the priority of the process, effects the priority of all of the threads within that process. The default priority for a thread is DEFAULT_PRIO_NP, which is no change from the process priority.

pthread thread state

℡╲_俬逩灬. 提交于 2020-01-13 05:16:24
问题 Is there a mechanism that I can use to tell if a pthread thread is currently running, or has exited? Is there a method for pthread_join() that is able to timeout after a specific period of time if the thread has not yet exited? 回答1: If you're only targeting linux, use http://www.kernel.org/doc/man-pages/online/pages/man3/pthread_tryjoin_np.3.html If you need something for any POSIX system, you can copy the "pthread_timedjoin" implementation in http://www.opengroup.org/onlinepubs/000095399

Can't provoke Priority Inversion in C++

大城市里の小女人 提交于 2020-01-12 10:19:28
问题 I'm trying to provoke Priority Inversion on a small C++ program for demonstration purposes but I can't: The low priority thread that holds the mutex is not preempted and keeps running on the critical section. This is what I'm doing: // let's declare a global mutex pthread_mutex_t my_mutex; ... int main(int argc, char **argv) { ... pthread_t normal_thread; pthread_t prio_thread; pthread_mutexattr_t attr; pthread_mutexattr_init (&attr); pthread_mutexattr_setprotocol (&attr, PTHREAD_PRIO_NONE);

Can't provoke Priority Inversion in C++

强颜欢笑 提交于 2020-01-12 10:19:13
问题 I'm trying to provoke Priority Inversion on a small C++ program for demonstration purposes but I can't: The low priority thread that holds the mutex is not preempted and keeps running on the critical section. This is what I'm doing: // let's declare a global mutex pthread_mutex_t my_mutex; ... int main(int argc, char **argv) { ... pthread_t normal_thread; pthread_t prio_thread; pthread_mutexattr_t attr; pthread_mutexattr_init (&attr); pthread_mutexattr_setprotocol (&attr, PTHREAD_PRIO_NONE);

Can't provoke Priority Inversion in C++

两盒软妹~` 提交于 2020-01-12 10:19:12
问题 I'm trying to provoke Priority Inversion on a small C++ program for demonstration purposes but I can't: The low priority thread that holds the mutex is not preempted and keeps running on the critical section. This is what I'm doing: // let's declare a global mutex pthread_mutex_t my_mutex; ... int main(int argc, char **argv) { ... pthread_t normal_thread; pthread_t prio_thread; pthread_mutexattr_t attr; pthread_mutexattr_init (&attr); pthread_mutexattr_setprotocol (&attr, PTHREAD_PRIO_NONE);

Pthreads - High memory usage

杀马特。学长 韩版系。学妹 提交于 2020-01-12 07:44:09
问题 I am programming something in C that creates a lot of Pthreads in Linux on a 256Mb system. I usually have +200Mb free. When I run the program with a low amount of threads it works, but once I make it create around 100 threads it gives errors because the system runs out of memory. I did several tests and each threads use almost 2Mb. The stack size of the threads is set to 16Kb. The code I use to create each thread: pthread_attr_t attr; pthread_attr_init(&attr); size_t stacksize; stacksize =

is it necessary to call pthread_mutex_destroy on a mutex?

半城伤御伤魂 提交于 2020-01-12 07:01:08
问题 I am using pthread_mutex_t in a C++ program, as follows: class Mutex : public noncopyable { public: Mutex() { pthread_mutex_init(&m_mutex, NULL); } void acquire() { pthread_mutex_lock(&m_mutex); } void release() { pthread_mutex_unlock(&m_mutex); } private: pthread_mutex_t m_mutex; }; (The class is not copyable - http://www.boost.org/doc/libs/1_53_0/boost/noncopyable.hpp) The thing that I don't understand - is it considered an error to not call pthread_mutex_destroy in the destructor? The