pthreads

undefined reference to `pthread_cancel'

淺唱寂寞╮ 提交于 2021-01-28 03:22:03
问题 I have written the following T class with pthread . When i compile this class using g++ -lpthread then it's working fine. But if i extend this class from another class A and compile all together it's returns an error; "undefined reference to pthread_cancel" Code: class T{ private: pthread_t thread; public: void start(){ pthread_create(&thread,NULL,&run,this); } void destroy_thread(){ pthread_cancel(thread); } static void* run(void*){} ~Thread(){ destroy_thread(); } }; Next class: class A:T{ A

freeing argument in function specified in pthread_create

风格不统一 提交于 2021-01-27 23:34:04
问题 I am writing a small server which creates a new thread to handle each new connection. I need to pass the socket to the function using the fourth argument of pthread_create. When trying to free the memory used for the socket i get a segfault. The communication works fine. I have tried passing a void* and also a void** (casted to void*, kind of ugly) This is the latest cludge i'm using while trying to figure this out, later if will be doing actual work in the respond function. #include <sys

Can I get a thread's stack address from pthread_self()

纵饮孤独 提交于 2021-01-27 20:23:45
问题 I want to get the stack address of a thread through some function to which we can pass pthread_self() . Is it possible? The reason I am doing this is because I want to write my own assigned thread identifier for a thread somewhere in its stack. I can write near the end of the stack (end of the stack memory and not the current stack address. We can ofcourse expect the application to not get to the bottom of the stack and therefore use space from there). In other words, I want to use the thread

Problem with thread-safe queue?

泪湿孤枕 提交于 2021-01-27 18:26:20
问题 I'm trying to write a thread-safe queue using pthreads in c++. My program works 93% of the time. The other 7% of the time it other spits out garbage, OR seems to fall asleep. I'm wondering if there is some flaw in my queue where a context-switch would break it? // thread-safe queue // inspired by http://msmvps.com/blogs/vandooren/archive/2007/01/05/creating-a-thread-safe-producer-consumer-queue-in-c-without-using-locks.aspx // only works with one producer and one consumer #include <pthread.h>

Enable ZTS on PHP without compiling

假如想象 提交于 2021-01-27 06:43:52
问题 When I try to install pthreads with PECL, the installation says that I must enable ZTS: configure: error: pthreads requires ZTS, please re-compile PHP with ZTS enabled I've installed PHP with Apt package manager and I don't want to have to replace that install with a self-compiled version. How can I enable ZTS without manual compiling? 回答1: You cannot; Zend Thread Safety is a compile time, only, option. Either find a thread safe package being maintained by someone else, or build yourself. 来源:

Enable ZTS on PHP without compiling

爷,独闯天下 提交于 2021-01-27 06:41:32
问题 When I try to install pthreads with PECL, the installation says that I must enable ZTS: configure: error: pthreads requires ZTS, please re-compile PHP with ZTS enabled I've installed PHP with Apt package manager and I don't want to have to replace that install with a self-compiled version. How can I enable ZTS without manual compiling? 回答1: You cannot; Zend Thread Safety is a compile time, only, option. Either find a thread safe package being maintained by someone else, or build yourself. 来源:

Enable ZTS on PHP without compiling

旧时模样 提交于 2021-01-27 06:41:17
问题 When I try to install pthreads with PECL, the installation says that I must enable ZTS: configure: error: pthreads requires ZTS, please re-compile PHP with ZTS enabled I've installed PHP with Apt package manager and I don't want to have to replace that install with a self-compiled version. How can I enable ZTS without manual compiling? 回答1: You cannot; Zend Thread Safety is a compile time, only, option. Either find a thread safe package being maintained by someone else, or build yourself. 来源:

What does “Performing Test CMAKE_HAVE_LIBC_PTHREAD” failed actually mean?

情到浓时终转凉″ 提交于 2021-01-21 04:49:08
问题 The cmake partial output looks like this: -- Performing Test CMAKE_HAVE_LIBC_PTHREAD -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed 回答1: The lines -- Looking for pthread.h -- Looking for pthread.h - found -- Performing Test CMAKE_HAVE_LIBC_PTHREAD -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed -- Looking for pthread_create in pthreads -- Looking for pthread_create in pthreads - not found -- Looking for pthread_create in pthread -- Looking for pthread_create in pthread - found are

How to free memory allocated by thread-function in the main

限于喜欢 提交于 2021-01-04 07:16:13
问题 I have allocated heap memory in the thread function f1 , this storage is used to calculate the value in the heap region so that the main function can see it. Here is the thread function definition: void *f1(void *input){ int sum = (int*)malloc(sizeof(int)); /* Do calculation */ pthread_exit((void*)&sum); } In the above code, the sum is the heap allocated storage, whose address is passed as a return value to the sum1 in the main() . I join the thread in the main() like this: void *sum1;

How to free memory allocated by thread-function in the main

我怕爱的太早我们不能终老 提交于 2021-01-04 07:15:19
问题 I have allocated heap memory in the thread function f1 , this storage is used to calculate the value in the heap region so that the main function can see it. Here is the thread function definition: void *f1(void *input){ int sum = (int*)malloc(sizeof(int)); /* Do calculation */ pthread_exit((void*)&sum); } In the above code, the sum is the heap allocated storage, whose address is passed as a return value to the sum1 in the main() . I join the thread in the main() like this: void *sum1;