multithreading

c++11 multithreading issues with Android where some threads are not scheduled properly

喜欢而已 提交于 2020-01-21 07:32:25
问题 I am developing a VoIP based application which is multithreaded. For every socket there is a c++11 std::thread (including SSL read & write). The core module for data communication is in C++ which is called through JNI interface. My observation is that, once initializing the application after few seconds, some threads which were running earlier normally are not getting running time. If a certain thread is running then it keeps running for a while ranging from 3-4 seconds to 30-40 seconds.

Can C++11 tell if std::thread is active?

China☆狼群 提交于 2020-01-21 07:16:46
问题 To my surprise, a C++11 std::thread object that has finished executing, but has not yet been joined is still considered an active thread of execution. This is illustrated in the following code example (built on Xubuntu 13.03 with g++ 4.7.3). Does anyone know if the C++11 standard provides a means to detect if a std::thread object is still actively running code? #include <thread> #include <chrono> #include <iostream> #include <pthread.h> #include <functional> int main() { auto lambdaThread =

What are atomic operations for newbies?

那年仲夏 提交于 2020-01-21 05:11:04
问题 I am a newbie to operating systems and every answer I've found on Stackoverflow is so complicated that I am unable to understand. Can someone provide an explanation for what is an atomic operation For a newbie? My understanding: My understanding is that atomic operation means it executes fully with no interruption ? Ie, it is a blocking operation with no scope of interruption? 回答1: Pretty much, yes. "Atom" comes from greek "atomos" = "uncuttable", and has been used in the sense "indivisible

Are threads waiting on a lock FIFO?

喜欢而已 提交于 2020-01-21 04:39:21
问题 Let's say I have the following code static class ... { static object myobj = new object(); static void mymethod() { lock(myobj) { // my code.... } } } Then let's say that while thread1 has the lock thread2 tries to run mymethod. Will it wait for the lock to be released or throw an exception? If it does wait, is order ensured so that if additional threads come in they are FIFO? 回答1: Updated my answer: They are queued, but the order is not guaranteed to be FIFO. Check out this link: http://www

How to Sleep a thread until callback for asynchronous function is received?

南楼画角 提交于 2020-01-21 01:47:07
问题 I have a function that needs to be executed only when a callback is received from asynchronous function. Like I call asynchronous function Stop() and soon after that I call asynchronous function Start() . The Issue before Stop CallBack is received Start() is called and thus I am getting issues. Also I can not separate the calling of two functions Like I can not do this.: public void SomeFunction() { Stop(); } public void Stop_CallBack(eventargs e) { Start(); } I have to do this: public void

Java: How can a thread wait on multiple objects?

[亡魂溺海] 提交于 2020-01-21 01:05:07
问题 A thread can use Object.wait() to block until another thread calls notify() or notifyAll() on that object. But what if a thread wants to wait until one of multiple objects is signaled? For example, my thread must wait until either a) bytes become available to read from an InputStream or b) an item is added to an ArrayList . How can the thread wait for either of these events to occur? EDIT This question deals with waiting for multiple threads to complete -- my case involves a thread waiting

QThread blocking main application

匆匆过客 提交于 2020-01-20 22:14:06
问题 I have a simple form UI that has a slot for a button, starting a thread: void MainWindow::LoadImage() { aThread->run(); } And the run() method looks like this: void CameraThread::run() { qDebug("Staring Thread"); while(1) { qDebug("ping"); QThread::sleep(1); } } When I click the button that calls LoadImage(), the UI becomes unresponsive. I periodically see the "ping" message as the debug output but the UI hangs, does not respond to anything. Why is my thread not running separately?

Why is raising an NSException not bringing down my application?

元气小坏坏 提交于 2020-01-20 22:06:31
问题 The Problem I'm writing a Cocoa application and I want to raise exceptions that will crash the application noisily. I have the following lines in my application delegate: [NSException raise:NSInternalInconsistencyException format:@"This should crash the application."]; abort(); The problem is, they don't bring down the application - the message is just logged to the console and the app carries on it's merry way. As I understand it, the whole point of exceptions is that they're fired under

Java-Thread Vs Runnable [duplicate]

爱⌒轻易说出口 提交于 2020-01-20 18:09:28
问题 This question already has answers here : “implements Runnable” vs “extends Thread” in Java (42 answers) Closed 5 years ago . While reading through the significant difference between Thread and Runnable from here, I encountered a difference that is: When you extends Thread class, each of your thread creates unique object and associate with it. where as When you implement Runnable, it shares the same object to multiple threads. . There is code give : class ImplementsRunnable implements Runnable

Why is UncaughtExceptionHandler not called by ExecutorService?

你离开我真会死。 提交于 2020-01-20 12:52:10
问题 I've stumbled upon a problem, that can be summarized as follows: When I create the thread manually (i.e. by instantiating java.lang.Thread ) the UncaughtExceptionHandler is called appropriately. However, when I use an ExecutorService with a ThreadFactory the handler is ommited. What did I miss? public class ThreadStudy { private static final int THREAD_POOL_SIZE = 1; public static void main(String[] args) { // create uncaught exception handler final UncaughtExceptionHandler exceptionHandler =