pthreads

Portability of pthreads-win32 over various windows compilers

回眸只為那壹抹淺笑 提交于 2020-01-12 04:58:18
问题 I'm using pthreads-win32 to allow threading support for windows. I have a cross platform project that uses pthreads and I want to make it work on windows with various compilers and different OS versions. At least, according to the documentation pthreads-win32 should work with MSVC and even MSVC builds provided. But I don't know if the library is tested with latest MSVC compilers like MSVC-2008 and if it is supported under 64bit windows. From Your own experience are you aware of any issues

Portability of pthreads-win32 over various windows compilers

半城伤御伤魂 提交于 2020-01-12 04:58:04
问题 I'm using pthreads-win32 to allow threading support for windows. I have a cross platform project that uses pthreads and I want to make it work on windows with various compilers and different OS versions. At least, according to the documentation pthreads-win32 should work with MSVC and even MSVC builds provided. But I don't know if the library is tested with latest MSVC compilers like MSVC-2008 and if it is supported under 64bit windows. From Your own experience are you aware of any issues

Lightweight spinlocks built from GCC atomic operations?

岁酱吖の 提交于 2020-01-12 04:40:13
问题 I'd like to minimize synchronization and write lock-free code when possible in a project of mine. When absolutely necessary I'd love to substitute light-weight spinlocks built from atomic operations for pthread and win32 mutex locks. My understanding is that these are system calls underneath and could cause a context switch (which may be unnecessary for very quick critical sections where simply spinning a few times would be preferable). The atomic operations I'm referring to are well

how to terminate a sleeping thread in pthread?

会有一股神秘感。 提交于 2020-01-12 02:21:12
问题 I have thread which sleeps for a long time, then wakes up to do something, then sleep again, like this: while(some_condition) { // do something sleep(1000); } How could I make this thread exit gracefully and QUICKLY? I tried to use pthread_cancel() , but sleeping threads could not be canceled. I also tried changing the condition of the while loop, but it will still take long to exit. And I don't want to use pthread_kill() , since it may kill the thread when it's working. So, are there any

How do I create a global variable that is thread-specific in C using POSIX threads?

为君一笑 提交于 2020-01-11 17:07:11
问题 I am learning about POSIX threads and I have come to the section on Thread Specific Data. The book does an excellent example using a file descriptor. However, I wanted to do the same example on my own, except this time using a global variable. However, I am having some difficulty fully grasping this concept. What I want to do is the following: Create a global integer Declare a key for the global int in main: set global integer to be a value eg. 10 create a key for it without any clean up

pthread_kill() vs pthread_cancel() to terminate a thread blocked for I/O

和自甴很熟 提交于 2020-01-11 06:49:27
问题 In our server code we are using poll() system call for monitoring client sockets. The poll() is called with a large timeout value. So the thread calling poll() gets blocked for I/O. As per the flow, we have a scenario where we need to terminate thread that blocked in poll() from a different thread. I have came across pthread_kill() and pthread_cancel() functions, which can terminate the target thread blocked for I/O. By reading the man pages, both these functions seems to work fine. Few links

how are pthreads on linux seen by scheduler

萝らか妹 提交于 2020-01-11 03:05:27
问题 I've a question regarding pthread implementation on Linux. Suppose a process has 5 threads. Now how does the scheduler sees these threads (or doesnt see at all). e.g. When scheduler is invoked, does it only schedule the main process, and then its the onus of the main process to schedule between each of its thread. Or is it the other way, that scheduler schedules each thread as if it is a separate process. 回答1: For modern Linux (NPTL pthread implementation), the scheduler schedules threads, a

Am I forced to use pthread_cond_broadcast (over pthread_cond_signal) in order to guarantee that *my* thread is woken up?

柔情痞子 提交于 2020-01-11 01:29:07
问题 In the context of interfacing some QT GUI thread (a pthread thread) with some C code, I stumbled over the following problem: I launch the QT Gui thread and, before my C thread resuming its path, I need to make sure that all the graphical objects inside the QT Gui thread had been constructed and they are valid QObjects (since the C code will call QObject:connect() on those). Introduction let aside, the waiting is made through a pthread_cond_wait() + a condition variable + an associated mutex

When I kill a pThread in C++, do destructors of objects on stacks get called?

寵の児 提交于 2020-01-10 18:44:48
问题 I'm writing a multi-threaded C++ program. I plan on killing threads. However, I am also using a ref-counted GC. I'm wondering if stack allocated objects get destructed when a thread gets killed. 回答1: The stack does not unwind when you 'kill' a thread. Killing threads is not a robust way to operate - resources they have open, such as files, remain open until the process closes. Furthermore, if they hold open any locks at the time you close them, the lock likely remains locked. Remember, you

How to stop a running pthread thread?

大城市里の小女人 提交于 2020-01-10 03:03:28
问题 How can I exit or stop a thread immediately? How can I make it stop immediately when the user enters an answer? I want it to reset for every question. Here's my code where threading is involved int q1() { int timer_start; char ans[] = "lol"; char user_ans[50]; timer_start = pthread_create( &xtimer,NULL,(void*)timer_func,(void*)NULL); printf("What is the capital city of Peru?\n"); while(limit){ scanf("%s",user_ans); if(limit) { if(!strcmp(user_ans, ans)) { // printf("YAY!\n"); score++; // q2()