Spawn a multi-threaded Java program from a Windows command line program, spawner won't end until spawnee ends. How can I
By : Steve Stanferd
Date : March 29 2020, 07:55 AM
hope this fix your issue You have a problem with your exec task in that spawn is defaulting to false. From the NAnt documentation: code :
<property name="browser" location="C:/Program Files/Internet Explorer/iexplore.exe"/>
<property name="file" location="ant/docs/manual/index.html"/>
<exec executable="${browser}" spawn="true">
<arg value="${file}"/>
</exec>
|
Delete an object securely from a multi-threaded program
By : powerpowerx
Date : March 29 2020, 07:55 AM
like below fixes the issue What is missing here is the condition that dictates when thread processing is completed. Deletion of a particular object instance is not a good condition. You havent shown us where the object is deleted. If we could see this in the code, the extra context would be helpful. What I would suggest is instead of deleting the object, set a flag on the object (bool active() for example). This flag will then be checked by all threads, and when it indicates stop processing, then the threads will stop. Set this flag where you are currently deleting the Foo object. Then once all threads have stopped, delete the Foo object. code :
class Foo
{
public:
void lockMutex();
void unlockMutex();
// Active should be mutex protected as well
// Or you could consider using a pthread_rwlock
bool active() {return active_;}
void setActive(bool a) {active_ = a;}
private:
pthread_mutex_t mutex;
bool active_;
};
void* thread ( void* fooPtr )
{
Foo* fooPointer = (Foo*) fooPtr;
while ( 1 )
{
if ( fooPointer->active() )
{
fooPointer->lockMutex();
/* some code, involving fooPointer */
fooPointer->unlockMutex();
}
else
{
pthread_exit ( NULL );
}
}
// somewhere else in the code
fooPointer->setActive(false);
}
|
Multi threaded program takes longer to execute than the Single Threaded Program
By : user32308
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further First of all, you are using processor-clock ticks to measure the performance, and by that measure any multi-threaded algorithm will be slower than an equivalent single-threaded algorithm. The reason is because this measure effectively counts the number of instructions that gets executed and threading always adds a little overhead to an algorithm. To get a proper measurement of performance, you need to measure the wall-clock time. This way, the measurement can accurately reflect the work that gets done in parallel by different cores/processors.
|
In Java, what's the best way to keep top 100 items in a multi-threaded program?
By : Akshay Jain
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further The fastest way to do this would be to use a heap (making sure it's a synchronized version, if it's multithreaded). A heap allows you to add elements in log time, and also to remove the smallest element in log time. The Java implementation of a heap is a PriorityQueue, or, for a synchronized version, a PriorityBlockingQueue. In your case, you're going to want a PriorityBlockingQueue .
|
GDB hangs when multi-threaded python extension is used to debug multi threaded program
By : kishore dasari
Date : March 29 2020, 07:55 AM
I wish this help you From this blog post: code :
import gdb
import threading
import pysigset, signal # Import these packages!
def plot_thread():
import time
while True:
print('Placeholder for a window event loop.')
time.sleep(1)
pass
pass
class PlotterCommand(gdb.Command):
def __init__(self):
super(PlotterCommand, self).__init__("plot",
gdb.COMMAND_DATA,
gdb.COMPLETE_SYMBOL)
self.dont_repeat()
pass
def invoke(self, arg, from_tty):
with pysigset.suspended_signals(signal.SIGCHLD): # Disable signals here!
plot_thread_instance=threading.Thread(target=plot_thread)
plot_thread_instance.daemon=True
plot_thread_instance.start()
pass
pass
pass
PlotterCommand()
|