(All of the following are simplified for brevity)
I have a static reference to a processing object.
The processor contains a function with which I can pass a Package object, which is the information being processed.
A package comes from a list of packages that need to be processed. These packages are fuzzy; there are no multiple references to the same object.
I run many threads so that I can process packages in toProcess in parallell. In Pop () streams, a package from the toProcess stack is available until the stack is empty.
Now my question: Can I take a chance that packagein Checkwill be overwritten by another thread or another thread "creates a copy" Check?
static class Program
{
static Processor processor = new Processor();
static Stack<Package> toProcess;
static Object sync = new Object();
static void RunThreads()
{
toProcess = GetPackages();
}
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)
{
}
}
class Package
{
}