Answer the question
In order to leave comments, you need to log in
Is there an advantage to running a task on two threads on the same core?
Given: there is a task consisting of two unrelated subtasks. There is a single-core processor. And 2 options for solving the problem:
1) write a program (one function) that first solves subtask 1, and then subtask 2, one after the other sequentially in one thread.
2) write a program of two functions, each function will solve its own subtask, and call these functions at the same time, that is, by creating a separate thread for each and starting parallel execution.
Question: in what case will the entire task (both subtasks) be completed faster?
UPDATE: additional questions:
1) professorweb.ru/my/csharp/thread_and_files/1/1_16.php
The value of the maximum allowed number of threads in the pool can change. For a dual-core CPU, it defaults to 1023 worker threads and 1000 I/O threads.
As more cores are added, tasks begin to break into smaller pieces. Accordingly, worker threads often turn to the global queue, the load on which is clearly increasing - the lock makes itself felt.
Increasing the number of cores in the system is similar to increasing the number of participants, since tasks will be divided into smaller pieces and, due to frequent access to the global queue, the need for synchronization will increase.
Answer the question
In order to leave comments, you need to log in
In my opinion, the 1st option will be faster, since no time will be spent on context switching. So there may not be an advantage when it comes to some abstract computational problem. But in practice, acceleration can be when there is work with a network or data storage devices.
This is my guess.
The number of nuances that can affect the result in your particular case is so large that it is cheaper to write two options, measure and compare.
The main postulate in the work on improving productivity: MOM - measure, optimize, monitor.
In general, "(.+)(?P< volume>\d+)?(\s?pcs)?$" to pull out a number is overkill. Why such a complex expression?
m = re.search('(\d+)[\s]?шт', 'Коробка шт с кирпичами 10 шт;')
m.group(1)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question