multithreading

Helgrind for Windows?

蓝咒 提交于 2020-01-24 13:03:08
问题 Helgrind is a Valgrind tool for detecting synchronisation errors in C, C++ and Fortran programs that use the POSIX pthreads threading primitives. Anyone knows an equivalent tool for windows? After googling a bit I haven't found anything... 回答1: For the people that eventually should land there: I've found that: Intel thread checker: should be pretty similar to Hellgrind. 回答2: The only thing of heard of in this area is CHESS, from Microsoft Research. Never used it though. No idea if its

How to Unit-Test Thread which takes time to perform action

感情迁移 提交于 2020-01-24 12:59:25
问题 I have Thread which runs while the program runs and polls a queue and check whether it has object and if yes then it calls method on the object Here is the code : while(isRunning){ synchronized (loginQueue) { if(loginQueue.peek() != null) { Object[] loginObjectWithConnection = loginQueue.poll(); tryLogin(loginObjectWithConnection); } } try { Thread.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); } } Here is the tryLogin method private void tryLogin(Object[]

Threading with Callback example does not work.

旧城冷巷雨未停 提交于 2020-01-24 12:34:06
问题 I am working on this example, but I am unable to mesh the callback and the threading. What I want is this. 1) Press button 2) Start the progress bar running 3) Call to a new thread to perform some long running process 4) A callback on the long running process should trigger the progress bar to stop. Below I have something...Although the callback parameter for DoSomethingInThread comes in as null. The StopProgressBar() acts on the ProgressBar control, so it cannot be static. static bool done;

In run method, how to find from where start was called?

◇◆丶佛笑我妖孽 提交于 2020-01-24 12:22:30
问题 I am debugging some code. My debugger shows that the origin of code is from Thread.run(). I need to know from which part of code Thread.start() was called! Is there a way to find this out? 回答1: You can use new Throwable().getStackTrace() to get a full stack trace. To get the start stack you must extend Thread , one of the few times it is actually necessary to do so (mostly using Runnable is preferred). class C extends Thread { StackTraceElement[] constructed; StackTraceElement[] started;

In run method, how to find from where start was called?

拈花ヽ惹草 提交于 2020-01-24 12:20:29
问题 I am debugging some code. My debugger shows that the origin of code is from Thread.run(). I need to know from which part of code Thread.start() was called! Is there a way to find this out? 回答1: You can use new Throwable().getStackTrace() to get a full stack trace. To get the start stack you must extend Thread , one of the few times it is actually necessary to do so (mostly using Runnable is preferred). class C extends Thread { StackTraceElement[] constructed; StackTraceElement[] started;

Call the method of Java class which implements runnable after creating its thread object

旧巷老猫 提交于 2020-01-24 12:17:35
问题 I have a java class SomeClass implements Runnable Which has a method display(). When I create a thread of this class Thread thread1 = new Thread(new SomeClass()); Now how I can call the display() method using the thread instance? 回答1: You will end up calling start() on thread1 . SomeClass will override run() method which in turn need to call display() method. This way when you call start() , run method of SomeClass() object will be invoked and display() method will be executed. Example:

To implement graceful shutdown check locking on async calls, or handle exceptions?

吃可爱长大的小学妹 提交于 2020-01-24 12:12:08
问题 I'm developing a Java app that for much of the time, including the point of shutdown, is having to deal with a flood of incoming asynchronous calls from a foreign framework. During normal operation these incoming calls then need to be dispatched to another framework, again asynchronously. At the moment I'm having my module be a "good" citizen and do some locking around a shutdown flag which, once set, will gracefully cease the dispatch of any further outgoing calls. The troubling thing is

To implement graceful shutdown check locking on async calls, or handle exceptions?

一笑奈何 提交于 2020-01-24 12:12:08
问题 I'm developing a Java app that for much of the time, including the point of shutdown, is having to deal with a flood of incoming asynchronous calls from a foreign framework. During normal operation these incoming calls then need to be dispatched to another framework, again asynchronously. At the moment I'm having my module be a "good" citizen and do some locking around a shutdown flag which, once set, will gracefully cease the dispatch of any further outgoing calls. The troubling thing is

How to completely switch off threading in TBB code

≯℡__Kan透↙ 提交于 2020-01-24 12:06:29
问题 Note: this is NOT a duplicate of this quesiton. Given a complex software parallelized with TBB, how do I completely switch off threading? I'm aware of the task_scheduler_init: int nthreads = tbb::task_scheduler_init::default_num_threads(); const char* cnthreads = getenv("TBB_NUM_THREADS"); if (cnthreads) nthreads = std::max(1, atoi(cnthreads)); tbb::task_arena arena(nthreads, 1); tbb::task_scheduler_init init(nthreads); However, this solution (related to this) does not switch off threading.

Android Lunar Lander thread handling alternatives

回眸只為那壹抹淺笑 提交于 2020-01-24 10:59:07
问题 Like many of the novices of android programming, I used Lunar Lander as a guide for implementing the SurfaceView. I'm practicing by creating a version of PONG. The basic structure of the code is the same as LunarLander. Obviously, I soon discovered the bug that was in Lunar Lander. The immediate way I got around this is by instantiating a new Thread object in SurfaceCreated() and starting it, when the original thread can't be started (which incidentally, is the same method that a lot of