pthreads

c, linux - using pthread.h in kernel [closed]

笑着哭i 提交于 2020-01-07 09:48:40
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . I'm trying to test the validity of a 9*9 sudoku problem and the results should be printed via printk(KERN_INFO "blablabla") . I've tried two methods to compile my c file, make and gcc myfile.c myfile -o -lpthread . However, none of them worked. When I called make it threw me with

c++ async sometimes resulting in std::system_error , and sometimes not

这一生的挚爱 提交于 2020-01-07 04:51:09
问题 I am trying to get the code example from there to work: https://solarianprogrammer.com/2012/10/17/cpp-11-async-tutorial/ int twice(int m){ return 2*m; } int main(){ std::vector< std::future<int> > futures; for(int i=0;i<10;++i){ futures.push_back(std::async(twice,i)); } for(auto &e:futures){ std::cout << e.get() << std::endl; } return 0; } This code results in: terminate called after throwing an instance of 'std::system_error' what(): Unknown error -1 I am using these flags for compilation:

C/unix Sockets: Segmentation fault (core dumbed) due to char pointer(?)

梦想的初衷 提交于 2020-01-07 04:40:33
问题 (maybe a duplicate of this question, but I find it quite hard to pinpoint my problem myself, so if the answer here is even close to identical to the other question, I'll try to delete the question) I want to make a client and a server program (with multiple clients using pthreads), where each client sends N numbers (input by the user) to the server, and the server returns the average of these numbers with an "ok message" if average>10, else the server returns a "not ok message". After the

pthread_join error code 3

独自空忆成欢 提交于 2020-01-07 02:58:10
问题 i have problem in my project. it throws me error code 3. I just add part of my code to let you see what I did. in main.cpp I declared on the threads then I send to initRequestThreads(in thread.h) to create the threads. then in main.cpp i let the main process to wait for it. main.cpp pthread_t *requestersThreads = new pthread_t[Length_Tasks]; requestsPool->initRequestThreads(&requestersThreads); void* status; // wait for all requests threads for(t=0; t<Length_Tasks; t++) { rc = pthread_join

Data race during nested thread creation

試著忘記壹切 提交于 2020-01-07 02:49:09
问题 While trying to create nested threads, helgrind reports several different types of data races. ==4429== Possible data race during write of size 8 at 0x5673830 by thread #13 ==4429== Locks held: none ==4429== at 0x4C379EF: memset (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so) ==4429== by 0x5060C85: get_cached_stack (allocatestack.c:250) ==4429== by 0x5060C85: allocate_stack (allocatestack.c:501) ==4429== by 0x5060C85: pthread_create@@GLIBC_2.2.5 (pthread_create.c:537) ==4429== by

Why do pthreads’ condition variable functions require a mutex?

ε祈祈猫儿з 提交于 2020-01-07 01:50:10
问题 I’m reading up on pthread.h ; the condition variable related functions (like pthread_cond_wait(3) ) require a mutex as an argument. Why? As far as I can tell, I’m going to be creating a mutex just to use as that argument? What is that mutex supposed to do? 回答1: It's just the way that condition variables are (or were originally) implemented. The mutex is used to protect the condition variable itself . That's why you need it locked before you do a wait. The wait will "atomically" unlock the

Why do pthreads’ condition variable functions require a mutex?

蹲街弑〆低调 提交于 2020-01-07 01:49:09
问题 I’m reading up on pthread.h ; the condition variable related functions (like pthread_cond_wait(3) ) require a mutex as an argument. Why? As far as I can tell, I’m going to be creating a mutex just to use as that argument? What is that mutex supposed to do? 回答1: It's just the way that condition variables are (or were originally) implemented. The mutex is used to protect the condition variable itself . That's why you need it locked before you do a wait. The wait will "atomically" unlock the

How to kill all subprocess created with pthread_create after cancelling a thread?

孤人 提交于 2020-01-06 18:12:27
问题 I have the following code and I make ps aux | grep myprogram in each step of the main() code of myprogram (name of the application I build). At the beggining of the execution of myprogram , the ps aux | grep myprogram show only 1 time the myprogram in the list after cancelling a thread that I created in the begging of the main() , the ps aux | grep myprogram show the myprogram twice and I expected to get only 1. Could some one explain this behaviour? and how to return to the initial situation

How to kill all subprocess created with pthread_create after cancelling a thread?

放肆的年华 提交于 2020-01-06 18:12:09
问题 I have the following code and I make ps aux | grep myprogram in each step of the main() code of myprogram (name of the application I build). At the beggining of the execution of myprogram , the ps aux | grep myprogram show only 1 time the myprogram in the list after cancelling a thread that I created in the begging of the main() , the ps aux | grep myprogram show the myprogram twice and I expected to get only 1. Could some one explain this behaviour? and how to return to the initial situation

thread_cancel and blocking function as cond_wait

[亡魂溺海] 提交于 2020-01-06 14:13:56
问题 I have my main process send pthread_cancel to another thread which is waiting for a condition to happen with cond_wait(&condition) . On the pthread_cancel they are saying : Deferred cancel ability means that cancellation will be delayed until the thread next calls a function that is a cancellation point. But often those function are blocking function. Then my question is the thread cancelled only after that thread has been unblock (in my example by a broadcast or a signal) or it would see