pthreads

How are POSIX cancellation points supposed to behave?

此生再无相见时 提交于 2019-12-31 21:53:08
问题 I've been looking at glibc/nptl's implementation of cancellation points, and comparing it to POSIX, and unless I'm mistaken it's completely wrong. The basic model used is: int oldtype = LIBC_ASYNC_CANCEL(); /* switch to asynchronous cancellation mode */ int result = INLINE_SYSCALL(...); LIBC_CANCEL_RESET(oldtype); According to POSIX: The side-effects of acting upon a cancellation request while suspended during a call of a function are the same as the side-effects that may be seen in a single

Multiplatform multiprocessing?

◇◆丶佛笑我妖孽 提交于 2019-12-31 03:17:37
问题 I was wondering why in the new C++11 they added threads and not processes. Couldn't have they done a wrapper around platform specific functions? Any suggestion about the most portable way to do multiprocessing? fork()? OpenMP? 回答1: If you could use Qt, QProcess class could be an elegant platform independent solution. 回答2: If you want to do this portably I'd suggest you avoid calling fork() directly and instead write your own library function that can be mapped on to a combination of fork()

How should a PHP thread store its data?

删除回忆录丶 提交于 2019-12-31 01:52:12
问题 So I have been googling and reading up and down the internet about PHP pthreads3 and how they are supposed to store data. (Or rather, how they are not) It seems to me that the only way for a thread to store its data properly is to create a new Threaded object and send it to the thread. The thread can then use this Threaded object to store nearly any data. My question, and biggest issue with grasping PHP threads: Is it possible to have the thread create its own storage objects when it wants? I

How should a PHP thread store its data?

自作多情 提交于 2019-12-31 01:52:08
问题 So I have been googling and reading up and down the internet about PHP pthreads3 and how they are supposed to store data. (Or rather, how they are not) It seems to me that the only way for a thread to store its data properly is to create a new Threaded object and send it to the thread. The thread can then use this Threaded object to store nearly any data. My question, and biggest issue with grasping PHP threads: Is it possible to have the thread create its own storage objects when it wants? I

POSIX threads and fairness (semaphores)

荒凉一梦 提交于 2019-12-30 11:33:34
问题 I have created a program in C that creates 2 buffers. The buffer indices hold single characters, 'A' or 'b' etc... In order to learn more about multithreading, I created a set of semaphores based on the producer/consumer problem to produce characters and consume characters from the buffers. I have 3 producer threads for each buffer and 10 consumer threads. The consumers take one item from each buffer, then report it (freeing the memory of the consumed item also). Now, from what I've read, sem

Pthread Condition Variables not Signalling even though set to PTHREAD_PROCESS_SHARED

时光总嘲笑我的痴心妄想 提交于 2019-12-30 11:23:13
问题 I'm having trouble with shared memory using condition variables and mutexes accross files. My research led me to here Share condition variable & mutex between processes: does mutex have to locked before? The solution that the OP posted, doesn't work if you run two completely separate executables. I tried his methods towards my own problem and two seperate processes just would not signal to each other. So to confirm that the OPs code actually works, as seen below i have copied his code and

Why is std::mutex taking a long, highly irregular amount of time to be shared?

被刻印的时光 ゝ 提交于 2019-12-30 11:03:50
问题 This code demonstrates that the mutex is being shared between two threads, but one thread has it nearly all of the time. #include <thread> #include <mutex> #include <iostream> #include <unistd.h> int main () { std::mutex m; std::thread t ([&] () { while (true) { { std::lock_guard <std::mutex> thread_lock (m); sleep (1); // or whatever } std::cerr << "#"; std::cerr.flush (); } }); while (true) { std::lock_guard <std::mutex> main_lock (m); std::cerr << "."; std::cerr.flush (); } } Compiled with

learning threads on linux

て烟熏妆下的殇ゞ 提交于 2019-12-30 10:38:42
问题 Linux is a new platform to me. I've coded on Windows in c++ for a number of years and have become comfortable with multithreading on that platform. Along comes C++11 at a time when I need to learn c++ on the linux platform. Linux appears to use pthreads for the most part - okay there's also boost::threads and QT have their own threads too. But with C++11 comes std::thread, a whole new (cross platform and C++ standard) way to do threads. So I guess I'll have to learn pthreads and std::threads.

How to draw opengl graphics from different threads?

女生的网名这么多〃 提交于 2019-12-30 10:05:12
问题 I want to make an opengl application that shows some 3d graphics and a command-line. I would like to make them separate threads, because they both are heavy processes. I thought that I could approach this with 2 different viewports, but I would like to know how to handle the threads in opengl. According to what I've been reading, Opengl is asynchronous, and calling its functions from different threads can be very problematic. Is there a way that I could use to approach this problem? Ideally,

how can I tell if pthread_self is the main (first) thread in the process?

社会主义新天地 提交于 2019-12-30 08:15:00
问题 background: I'm working on a logging library that is used by many programs. I'm assigning a human-readable name for each thread, the main thread should get "main", but I'd like to be able to detect that state from within the library without requiring code at the beginning of each main() function. Also note: The library code will not always be entered first from the main thread. 回答1: This is kinda doable, depending on the platform you're on, but absolutely not in any portable and generic way..