multithreading

Why does multiprocessing.Lock() not lock shared resource in Python?

巧了我就是萌 提交于 2020-02-03 04:21:08
问题 Supposing I have a very big text file consisting of many lines that I would like to reverse. And I don't care of the final order. The input file contains Cyrillic symbols. I use multiprocessing to process on several cores. I wrote such program: # task.py import multiprocessing as mp POOL_NUMBER = 2 lock_read = mp.Lock() lock_write = mp.Lock() fi = open('input.txt', 'r') fo = open('output.txt', 'w') def handle(line): # In the future I want to do # some more complicated operations over the line

When does concurrency/multithreading help improve performance?

余生颓废 提交于 2020-02-03 01:53:13
问题 I have been planning to use concurrency in project after learning it indeed has increased through put for many. Now I have not worked much on multi threading or concurrency so decided to learn and have a simple proof of concept before using it in actual project. Below are the two examples I have tried: 1. With use of concurrency public static void main(String[] args) { System.out.println("start main "); ExecutorService es = Executors.newFixedThreadPool(3); long startTime = new Date().getTime(

Async programming, why doesn't the code get executed

牧云@^-^@ 提交于 2020-02-02 15:59:55
问题 I'm quite new to async programming, but I need it badly inside on of our applications. I'm just trying something inside a Console Application but it doesn't seem to work. I'm aware that a Console Application doesn't support async out of the box as there isn't a main thread like a UI thread in a WinForms Application. Anyway, here's what I'm trying: I have an async method which contains the following logic: public static async Task MainAsync() { Console.WriteLine("This method is being executed.

Async programming, why doesn't the code get executed

情到浓时终转凉″ 提交于 2020-02-02 15:59:14
问题 I'm quite new to async programming, but I need it badly inside on of our applications. I'm just trying something inside a Console Application but it doesn't seem to work. I'm aware that a Console Application doesn't support async out of the box as there isn't a main thread like a UI thread in a WinForms Application. Anyway, here's what I'm trying: I have an async method which contains the following logic: public static async Task MainAsync() { Console.WriteLine("This method is being executed.

What happens to a lock during an Invoke/BeginInvoke? (event dispatching)

泄露秘密 提交于 2020-02-02 15:04:20
问题 Just to put the questions upfront (please no comments about the bad architecture or how to revise - suppose this is what it is): How does the "lock" statement apply when using Invoke/BeginInvoke Could the following code result in a deadlock? Suppose I have the following BindingList that I need to update on the GUI Thread: var AllItems = new BindingList<Item>(); I want to make sure that all updates to it are synchronized. Suppose I have the following subroutine to do some calculations and then

What happens to a lock during an Invoke/BeginInvoke? (event dispatching)

做~自己de王妃 提交于 2020-02-02 15:00:33
问题 Just to put the questions upfront (please no comments about the bad architecture or how to revise - suppose this is what it is): How does the "lock" statement apply when using Invoke/BeginInvoke Could the following code result in a deadlock? Suppose I have the following BindingList that I need to update on the GUI Thread: var AllItems = new BindingList<Item>(); I want to make sure that all updates to it are synchronized. Suppose I have the following subroutine to do some calculations and then

Reduce execution time on huge list generation

无人久伴 提交于 2020-02-02 12:23:11
问题 I'm fairly new to Python, and I'm trying to write some huge lists (with random letters inside). Actually it takes me around 75 - 80 seconds on my machine for 2,000,000 lines. import timeit import random, string global_tab = [] global_nb_loop = 2000000 print("Generate %d lines" % global_nb_loop) global_tab = [] for x in range(global_nb_loop): global_tab.append(("".join( [random.choice(string.ascii_letters) for i in range(15)] ), "".join( [random.choice(string.digits) for i in range(2)])))

What WPF threading approach should I go with?

时光总嘲笑我的痴心妄想 提交于 2020-02-02 11:40:13
问题 I'm writing a WPF application (new technique, mostly I've been writing in WinForms). My goal is to make UI responsive whole time, and I've read that it can be achived using Threading/BackgroundWorker. I think that I should use background worker to put there time consuming methods. But I plan to use method *m_AddLog(string logText)* which should append text to textbox. This method I want to call from main UI thread aswell as from background worker, so messages would be sent immediatelly while

How to force cpu core to flush store buffer in c?

主宰稳场 提交于 2020-02-02 11:35:11
问题 I have an application which has 2 threads , thread A affinity to core 1 and thread B affinity to core 2 , core 1 and core 2 are in the same x86 socket . thread A do a busy spin of integer x , thread B will increase x under some conditions , When thread B decide to increase x , it invalidate the cache line where x located ,and according to x86 MESI protocal , it store new x to store buffer before core2 receive invalidate ack, then after core2 receive invalidate ack , core2 flush store buffer .

Painting on GtkScrolledWindow or GtkEventBox

只愿长相守 提交于 2020-02-02 04:07:26
问题 Using GTK, I'm trying to overlay a "More" prompt (but it could just as well be any drawing object) in the corner of a GtkTextView contained within a GtkScrolledWindow . I draw the prompt in the handler for the expose signal of the text view. It works, but when I scroll the window I get artifacts: the prompt is moved along with the contents of the text view and not erased. In order to get rid of the artifacts I trigger a redraw after each scroll. This mostly works, but you can still see the