Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8730105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:57:10+00:00 2026-06-13T08:57:10+00:00

Im trying to implement multi-threading in my application that makes a lot of float

  • 0

Im trying to implement multi-threading in my application that makes a lot of float number calculations (neural network).

I wrote function that makes necessary calculations and updates array outside that function.
My actual, single-thread code looks like this (simplified for better understanding):

class MyClass
{
    // this array after all calculations should contain 
    // result of only one calculation, 
    // that returned smallest value in one of array fields 
    // (smallest neural network error)
    float[] bestResult;

    // runs calculations on all "sets of data"
    public void findBestResult(void)
    {
        foreach (something...) // data rows from database cached in one array
        {
            calculate(x[]);
        }
    }

    // calculates one "set of data"
    public void calculateAndUpdateResultIfBetter(float[] inputData)
    {

        if (bestResult[0] > calculatedData[0])
             bestResult = calculatedData; // update only if condition is true
    }

}

Im low level programmer, i don’t know how to use advanced (?) .NET threading techniques, that use Synchronize etc. I know how to create one additional thread for something and update some controls on form by using delegates.

I have no idea how to work with 2-8 threads doing exactly same thing and competing with each other.

The question 1 is – can you help me with this? I don’t know how to start. SOLVED BY Niko Drašković

EDIT:
The question 2 is – will lock() method lock my array for read and write?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:57:11+00:00Added an answer on June 13, 2026 at 8:57 am

    You use the lock statement to prevent different threads to run the same code at the same time. You would need a reference to use as an identifier for the lock. It’s common to create a simple object that is used only for the locking:

    float[] bestResult;
    object sync = new Object();
    

    Then around the code that accesses the array you use lock:

    lock (sync) {
      if (bestResult[0] > calculatedData[0]) {
        bestResult = calculatedData;
      }
    }
    

    You might want to have each thread first calculate the best value that it can see within the data that it is responsible for, and then combine those best values. If you run the locked code too often you will make the threads wait for each other, losing a lot of the reason for running separate threads in the first place.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement a multi-tenant application, that is - data of all
I am trying to implement multi-threading in my Java Mandelbrot application: This is what
I'm trying to implement multi-threading as suggested here: Spawn Multiple Threads for work then
I have a multi page form that I am trying to implement on my
I ned to implement the multi-linear regression in C#(3.0) by using the LinESt function
I'm trying to implement a server-client socket program in Java that can support multiple
Hi fellow android developers, I'm trying to implement a multi-pane layout as described here
I am trying to implement MVVM (Model View ViewModel) pattern for my WinForms application.
I've been trying to implement a dynamic multi-model form with accepts_nested_attributes_for in my rails
I am trying to implement core data entities in a multi-threaded environment. I understand

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.