Multithreading program does not work correctly on one-core processor

Multithreading program does not work correctly on one-core processor

By : Joe Polshaw
Date : November 22 2020, 12:01 PM
around this issue Why don't you use the ConcurrentDictionary of .NET4? The hard work of ensuring thread safety in dictionaries has already been done. Your code would be much cleaner and less error prone. Maybe it solves your problem, maybe it doesn't. (You still haven't described the symptoms of "not working". Does it run as a single-threaded app? Does it crash? Does it produce wrong data?)
code :
class LogStruct
    public ConcurrentDictionary<string, ulong> domainName;
    public ConcurrentDictionary<string, ulong> URL;
    public ConcurrentDictionary<string, ulong> domainData;
    public ConcurrentDictionary<string, ulong> errorCodes;

    public LogStruct()
        domainName = new ConcurrentDictionary<string, ulong> { };
        URL = new ConcurrentDictionary<string, ulong> { };
        domainData = new ConcurrentDictionary<string, ulong> { };
        errorCodes = new ConcurrentDictionary<string, ulong> { };

class CLogParser
    LogStruct m_logStruct;

    public CLogParser()
         m_logStruct = new LogStruct();

    public void ThreadProc(object param)
        string logName = (string)param;

        StreamReader file;
            file = new StreamReader(logName);
        string line;
        while ((line = file.ReadLine()) != null)//may be,something wrong here
            var space_pos = line.IndexOf(' ');
            if (space_pos > 0)
                string[] parameters = line.Split(new Char[] { ' '}, StringSplitOptions.RemoveEmptyEntries);
                string domainName = parameters[0];
                bool isMainPage = (parameters[4] == "\"-\"") ? true : false;
                string relativePageAddress = (isMainPage) ? "/" : parameters[5];
                Regex reg = new Regex(" \\d+");
                MatchCollection matches = reg.Matches(line);
                string errorCode = matches[1].Value;
                ulong pageSize = (matches.Count > 2) ? Convert.ToUInt64(matches[2].Value) : 0;
                string fullAdress = domainName + relativePageAddress;
                string fullErrCode = domainName + errorCode;

                if (m_logStruct.domainName.ContainsKey(domainName))
                    m_logStruct.domainData[domainName] += pageSize;
                    m_logStruct.URL.AddOrUpdate(fullAdress, 1, (key, oldVal) =>
                        return m_logStruct.URL[fullAdress];

                    m_logStruct.errorCodes.AddOrUpdate(fullErrCode, 1, (key, oldVal) =>
                        return m_logStruct.errorCodes[fullErrCode];
                    m_logStruct.domainName.AddOrUpdate(domainName, 1, ShallNeverHappen);
                    m_logStruct.domainData.AddOrUpdate(domainName, pageSize, ShallNeverHappen);
                    m_logStruct.URL.AddOrUpdate(fullAdress, 1, ShallNeverHappen);
                    m_logStruct.errorCodes.AddOrUpdate(fullErrCode, 1, ShallNeverHappen);

    public ulong ShallNeverHappen(String key, ulong existingVal) 
        throw new InvalidOperationException("This method is not expected to be called");

Share : facebook icon twitter icon
On dual-core processor, program runs quicker if another program is running at the same time!

On dual-core processor, program runs quicker if another program is running at the same time!

By : user2779475
Date : March 29 2020, 07:55 AM
This might help you There's a great talk by Joshua Bloch on difficulties with this kind of benchmarks. Here's an article that summarizes it (there's a link for the talk there too): http://java.dzone.com/articles/joshua-bloch-performance
General conclusion: processors and VMs do all kinds of complex and unpredictable optimizations, that affect benchmarks in counterintuitive ways, such as the one that you described. In any particular case, there is really no way to determine what is causing an anomaly, due to the enormous complexity of the system. Only way to improve performance is using experimentation and statistical analysis of benchmark data.
Java multithreading in a laptop having quad-core processor

Java multithreading in a laptop having quad-core processor

By : LÊ LÊ
Date : March 29 2020, 07:55 AM
will help you Even a single CPU can do "multiple things at the same time" in a loose sense, but they are not truly in parallel. You can start 100 threads to run on a single core and they will get time slices during which each of them can run a few instructions, thus creating the impression that they are all executing at the same time.
As I've said in another SO post: multithreading on dual core machine?
code :
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

class ThreadTask implements Runnable {

    private int total = 0;

    public ThreadTask(int total) {
        this.total = total;

    public void run() {
        int value = 0;
        for(int i = 0; i < total; i++) {
            value = i * i;

public class Test {

    public static void main(String[] args) throws InterruptedException {

        int total = 1000000000;

        long start = System.currentTimeMillis();
        long value = 0;
        for(int i = 0; i < total; i++) {
            value = i * i;
        long stop = System.currentTimeMillis();

        System.out.println((stop - start) + " ms");

        ExecutorService exec = Executors.newFixedThreadPool(4);
        start = System.currentTimeMillis();
        for(int i = 0; i < 4; i++) {
            exec.submit(new ThreadTask(total / 4));
        exec.awaitTermination(10, TimeUnit.SECONDS);
        stop = System.currentTimeMillis();

        System.out.println((stop - start) + " ms");     
Get GNU Octave to work with a multicore processor. (Multithreading)

Get GNU Octave to work with a multicore processor. (Multithreading)

By : Zeal Patel
Date : March 29 2020, 07:55 AM
With these it helps Solution
Octave itself is a single-thread application that runs on one core. You can get octave to use some libraries like ATLAS which utilize multiple cores. So while Octave only uses one core, when you encounter a heavy operation, octave calls functions in ATLAS that utilize many CPU's.
code :
bigMatrixA = rand(3000000,80);
bigMatrixB = rand(80,30);
bigMatrixC = bigMatrixA * bigMatrixB;
Without Atlas: Elapsed time is 3.22819 seconds.
With Atlas:    Elapsed time is 0.529 seconds.
How to use multithreading or any other .NET technology to scale a program performing network, disk and processor intensi

How to use multithreading or any other .NET technology to scale a program performing network, disk and processor intensi

By : MrCplusx2
Date : March 29 2020, 07:55 AM
This might help you The Problem: ,
The current solution works fine
Can this multithreading program work correctly on an one-core processor?

Can this multithreading program work correctly on an one-core processor?

By : Fecemel Gürbü
Date : March 29 2020, 07:55 AM
like below fixes the issue Yes. In general, you can happily run a process with more threads than physical processors - if anything, you run into more threading issues if you have multiple physical processor cores (as it is suddenly possibly for two (or more) things to happen in the same clock cycle.
Related Posts Related Posts :
  • X509Certificate2.Import with NCRYPT_ALLOW_PLAINTEXT_EXPORT_FLAG
  • Model expands on moving horizontally in unity
  • Custom response when Model binding fails ASP.NET Core API
  • Can you Serialize inside a set of Attributes by Set of Attributes?
  • ASP.NET Web API 2 - Filter POST requests by Query String
  • ValidationAttribute injecting services for unobtrusive client validation
  • UWP - Middle Mouse Wheel Button Click Event Handler
  • .Net Core 2.2 Cookie Authentication Problem
  • How have more than two expands in restier asp.net
  • Autofac Resolve with TypedParameter always pick up first the same type parameter expected?
  • Regluar expression problem. It does not find the needed part of the string
  • How to make a Sum of values in a list for Charts? [ SOLVED ]
  • Nested HttpWebRequest in c#
  • How to read a struct containing array of structs from TwinCat to C#
  • HttpPostedFileBase gets content length to 0 when C# iterates the zipfile
  • xamarin forms HttpClient incomplete Json
  • How can i write more than one string in one line?
  • ASP.NET Core MVC equivalent of Start Action Specific Page
  • Dynamic grid row count and column count with XAML
  • How to query the first entry in each group in NHibernate
  • How can you migrate an entity framework project to .NET standard when the fluent configuration is using HasDatabaseGener
  • Program freezes when using RSA.ImportParameters() on android platform
  • SQL select query - no seconds or milliseconds in datetime
  • ASP.NET Core CORS combining policies; enablecors in controller vs midleware configuration
  • How to stop Firebase Realtime Database Unity SDK listener load all child data at start of application
  • How to offset the Y position of every second column in a Grid Control
  • Client side or server side error on SecurityTokenValidationException certificate expiration
  • if String is empty then data is not inserting
  • How to pass dynamic parameter and inject repository in ActionFilter in asp.net Core 2.2?
  • Select element where attribute contains a certain substring
  • How to get JSON response for column names in database table
  • How can I safely unsubscribe from an Action in one line?
  • How to change icon ( of main Form + another child forms) programatically in c# code while compilation
  • Why is the result of adding two null strings not null?
  • Getting deserialized values
  • What are difference between use invoke and synchronizationcontext.Post object?
  • Asynchronous Communication
  • No connectionString could be found in the test project application config file
  • Building a website that converts address to longitude and latitude and saves in the database
  • WPF Border shape
  • How to Add ItemArray to DataRow at a specific Location in DataTable
  • Try within Linq query
  • How to reduce the execution time?
  • What does T stands for in C#?
  • WPF MVVM Databinding with parameters?
  • How to apply a custom style to a control inside of a custom control template?
  • ASP.NET 4.5 data binding model SelectMethod throw error
  • How does the compiler recognise Nullable<T> to be a 'special type'?
  • Populate DataGridview upon ComboBox selection
  • KeyCommand disabled MenuItem
  • get the data that was returned from the stored procedure SQL Server 2008 silvelight C# Linq
  • Text boxes are not filling when the Form Loads, Windows Form Application
  • multiple input and multiple output in ssis with executing bat file
  • How to replace a string using the original matched value
  • Splitting Date from DateTime
  • How to manage multiple windows in MVVM
  • Setting active a Chrome window (C++)
  • Adding a Custom Task Pane to Word (Without using VSTO)
  • Session is set or not in ASP.NET
  • Not able to pass eval to javascript function
  • shadow
    Privacy Policy - Terms - Contact Us © festivalmusicasacra.org