multithreading

Java Thread Start-Stop-Start on same button click

巧了我就是萌 提交于 2021-02-07 10:33:40
问题 I am creating a simple java program with a GUI built with the help of window builder. The GUI consists of just a button. On button click,start a thread that will print to the random number infinitely until it is stopped by clicking the same button again. Here is my code LoopTest.java import javax.swing.*; import java.awt.*; import java.awt.event.*; public class LoopTest extends JFrame implements ActionListener {//****** private JButton startB, stopB; private JTextArea oa; Start sta; public

Calling a method in thread from another thread, python

雨燕双飞 提交于 2021-02-07 10:32:22
问题 How can I achieve communication between threads? I have one thread in which I do some stuff, then I need to call a method from an object that lives in the main program thread and this method should be executed in the main process: class Foo(): def help(self): pass class MyThread(threading.Thread): def __init__(self, connection, parser, queue=DEFAULT_QUEUE_NAME): threading.Thread.__init__(self) def run(self): # do some work # here I need to call method help() from Foo() # but I need to call it

How does Promise in javascript work under the hood? My Promise implementation doesn't work the same

℡╲_俬逩灬. 提交于 2021-02-07 09:33:47
问题 I am a newbie to JS and I am trying to understand how Promise should work under the hood. Here is a custom implementation that looks reasonably good to me: class MyPromise { constructor(executor) { this._resolutionQueue = []; this._rejectionQueue = []; this._state = 'pending'; this._value; this._rejectionReason; try { executor(this._resolve.bind(this), this._reject.bind(this)); } catch (e) { this._reject(e); } } _runRejectionHandlers() { while(this._rejectionQueue.length > 0) { var rejection

Create a Windows Form from a background Thread

烈酒焚心 提交于 2021-02-07 09:32:36
问题 I'm developing a VS Package and I have this problem: I have a Background-Thread which checks every few seconds for specific changes that have to be done. This includes changing the GUI of VS 2010, which works perfectly fine without an invoke for some reason. Anyway if I try to open a new Form, it opens, but it doesn't show anything, kind of crashes and doesn't respond. I've already tried Application.OpenForms[0].invoke( /* delegate to create the form */) . This works fine, but I don't have an

Create a Windows Form from a background Thread

戏子无情 提交于 2021-02-07 09:31:44
问题 I'm developing a VS Package and I have this problem: I have a Background-Thread which checks every few seconds for specific changes that have to be done. This includes changing the GUI of VS 2010, which works perfectly fine without an invoke for some reason. Anyway if I try to open a new Form, it opens, but it doesn't show anything, kind of crashes and doesn't respond. I've already tried Application.OpenForms[0].invoke( /* delegate to create the form */) . This works fine, but I don't have an

How does Promise in javascript work under the hood? My Promise implementation doesn't work the same

假装没事ソ 提交于 2021-02-07 09:31:05
问题 I am a newbie to JS and I am trying to understand how Promise should work under the hood. Here is a custom implementation that looks reasonably good to me: class MyPromise { constructor(executor) { this._resolutionQueue = []; this._rejectionQueue = []; this._state = 'pending'; this._value; this._rejectionReason; try { executor(this._resolve.bind(this), this._reject.bind(this)); } catch (e) { this._reject(e); } } _runRejectionHandlers() { while(this._rejectionQueue.length > 0) { var rejection

Could threading or multiprocessing improve performance when analyzing a single string with multiple regular expressions?

戏子无情 提交于 2021-02-07 09:20:58
问题 If I want to analyze a string using dozens of regular-expressions, could either the threading or multiprocessing module improve performance? In other words, would analyzing the string on multiple threads or processes be faster than: match = re.search(regex1, string) if match: afunction(match) else: match = re.search(regex2, string) if match: bfunction(match) else: match = re.search(regex3, string) if match: cfunction(match) ... No more than one regular expression would ever match, so that's

Could threading or multiprocessing improve performance when analyzing a single string with multiple regular expressions?

北慕城南 提交于 2021-02-07 09:20:57
问题 If I want to analyze a string using dozens of regular-expressions, could either the threading or multiprocessing module improve performance? In other words, would analyzing the string on multiple threads or processes be faster than: match = re.search(regex1, string) if match: afunction(match) else: match = re.search(regex2, string) if match: bfunction(match) else: match = re.search(regex3, string) if match: cfunction(match) ... No more than one regular expression would ever match, so that's

Could threading or multiprocessing improve performance when analyzing a single string with multiple regular expressions?

坚强是说给别人听的谎言 提交于 2021-02-07 09:20:30
问题 If I want to analyze a string using dozens of regular-expressions, could either the threading or multiprocessing module improve performance? In other words, would analyzing the string on multiple threads or processes be faster than: match = re.search(regex1, string) if match: afunction(match) else: match = re.search(regex2, string) if match: bfunction(match) else: match = re.search(regex3, string) if match: cfunction(match) ... No more than one regular expression would ever match, so that's

C++ Treiber Stack and atomic next pointers

为君一笑 提交于 2021-02-07 09:19:07
问题 The "Treiber Stack" is generally one of the simplest lock-free data structures, and so it is often used when teaching introductions to lock-free algorithms. I've seen many implementations of Treiber Stacks using C++ atomics. The algorithm itself is trivial, so the real challenge is handling all the other incidental details of lock-free data-structures, such as providing some way of performing safe memory reclamation, avoiding the ABA problem, and allocating nodes in a lock-free manner. This