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

  • SEARCH
  • Home
  • 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 8273447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:29:37+00:00 2026-06-08T07:29:37+00:00

I am not familiar with multithreading. Image I have a method to do some

  • 0

I am not familiar with multithreading. Image I have a method to do some intensive search on a string, and return 2 lists of integers as out parameters.

public static void CalcModel(string s, out List<int> startPos, out List<int> len)
    {
        // Do some intensive search
    }

The search on long string is very time consuming. So I want to split the string into several fragments, search with multithreads, and recombine the result (adjust the startPos accordingly).

How to integrate multithreading in this kinda process? Thanks

I forgot to mention the following two things:

  1. I want to set a string length cutoff, and let the code to decide how many fragments it needs.
  2. I had a hard time to associate the startPos of each fragments (on the original string) with the thread. How can I do that?
  • 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-08T07:29:38+00:00Added an answer on June 8, 2026 at 7:29 am

    Rather than get too bogged down in details, generally, you send each thread a “return object.” Once you’ve started all the threads, you block on them and wait until they are all finished.

    While each thread is running, the thread modifies its work object and terminates when it has produced the output.

    So roughly this (I can’t tell exactly how you want to split it up, so perhaps you can modify this):

    public class WorkItem {
        public string InputString;
        public List<int> startPos;
        public List<int> len;
    }
    
    public static void CalcLotsOfStrings(string s, out List<int> startPos, out List<int> len)
    {
        WorkItem wi1 = new WorkItem();
        wi1.InputString = s;
        Thread t1 = new Thread(InternalCalcThread1);
        t1.Start(wi1);
        WorkItem wi2 = new WorkItem();
        wi2.InputString = s;
        Thread t2 = new Thread(InternalCalcThread2);
        t2.Start(wi2);
    
        // You can now wait for the threads to complete or start new threads
        // When you're done, wi1 and wi2 will be filled with the updated data
        // but make sure not to use them until the threads are done!
    }
    
    
    public static void InternalCalcThread1(object item)
    {
        WorkItem w = item as WorkItem;
        w.startPos = new List<int>();
        w.len = new List<int>();
    
        // Do work here - populate the work item data
    }
    
    
    public static void InternalCalcThread2(object item)
    {
        // Do work here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im not familiar with jquery so any help would be appreciated, i have some
For those of you not familiar with interpolation search, it is method to search
I'm not familiar with beautifulsoup's encoding. when I tackle with some pages,some attribute is
I'm not familiar with Capistrano at all, I've just read some basic posts about
I am not familiar with regular expression. For a string, I want to replace
I'm not familiar with bitwise operators, but I have seem them used to store
Im not familiar with bitwise operations. This is an image manipulation algorithm. What is
I am not familiar with various XML formatting I have recieved XML document most
Not familiar with C, please correct me on any mistakes. here's some code: void
I'm not familiar with ASP, but am helping someone out with their website as

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.