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 8504489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:02:48+00:00 2026-06-11T02:02:48+00:00

(All of the below are simplified for brevity) I have a static reference to

  • 0

(All of the below are simplified for brevity)

I have a static reference to a processing object.

The Processor contains a function to which I can pass an object Package, which is the info to be processed.

The Package comes from a list of lots of packages which should be processed. These packages are unqique; there are not multiple references to the same object here.

I start many threads so that I can process the packages in toProcess in parallell. The threads Pop() an available Package from the toProcess stack until the stack is empty.

My question is now: Can I risk that package in Check is overwritten by another thread, or will the other thread “create a copy” of Check?

static class Program
{
    static Processor processor = new Processor();
    static Stack<Package> toProcess;
    static Object sync = new Object();

    static void RunThreads()
    {
        toProcess = GetPackages();
        //start many threads using the Work delegate
    }

    static void Work()
    {
        while(true)
        {
            Package p;
            lock(sync)
            {
                if(toProcess.Count == 0)
                   break;
                p = toProcess.Pop();
            }
            processor.Check(p);
        }
    }
}

class Processor
{
    public void Check(Package package)
    {
        //do many analyses on p and report results of p's analysis to elsewhere
    }
}

class Package
{
    //properties
}
  • 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-11T02:02:49+00:00Added an answer on June 11, 2026 at 2:02 am

    My question is now: Can I risk that package in Check is overwritten by another thread, or will the other thread “create a copy” of Check?

    It’s not really clear what you mean, but each independent call to Check will have its own package variable. That variable is local to not just that thread, but that invocation of Check (so recursive calls won’t change it either).

    Now if you pass the same Package reference to Check in multiple different threads, then yes, they will all be processing the same object, which may cause problems. But the package variables themselves will be independent in the different calls.

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

Sidebar

Related Questions

I have a list of divs similar to the simplified code below, which I've
Hi All below is the code which i use. <!DOCTYPE html PUBLIC -//W3C//DTD XHTML
I have an array of array like below with all numeric values. I want
All code below is a stand-alone working example (greatly simplified) of what I am
I have a page in JQuery mobile, which contains a form. The form has
As in the simplified code below, is checking that SendAsync() has finished transmitting all
All in the question title, and my simplified code below. According to the docs:
I have a complicated python server app, that runs constantly all the time. Below
Below is the simplified version of the Table. My query is select all the
I have an app using fragments, all of which are contained in a single

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.