Please see my comment to the question.
Sorry, it needs time to write solution which would not help you much anyway. So, just a few notes will be more useful:
"Different instanced of same threads" is absurd. If instances are different, they are not same threads at all. From the other hand, different threads can run the same function, or the also the same function on the same "this" object, but the "same function" has little significance for threads. However, same "this" is important, because then the threads get access to the same,
shared object, so the problem becomes the issue of
thread synchronization. You need to learn it:
Synchronization (computer science) — Wikipedia, the free encyclopedia[
^],
Overview of Synchronization Primitives[
^],
Thread Synchronization (C# and Visual Basic)[
^].
See also:
Mutual exclusion — Wikipedia, the free encyclopedia[
^].
Perhaps you simply fail to explain the problem properly, and the real problem related to what you called "different instances" meant to be different threads working with some shared objects.
Sorry to say that, but I don't really expect you to really understand all of the above, because you, for example, did not even try to create any thread in your code sample. And you did not even try to create a linked list, because you, essentiall, did not even try to link any of your nodes. This is much easier when you work with .NET references and hence GC takes care of lost references. Probably, you first need to learn the very basics of programming in general and not prepared for the interviews. As to the threading, you need to learn it only if you learn all the prerequisites. Then you can get to threding:
Multithreading (computer architecture) - Wikipedia, the free encyclopedia[
^],
Thread (computing) — Wikipedia, the free encyclopedia[
^],
Parallel computing — Wikipedia, the free encyclopedia[
^],
Managed Threading[
^],
Threading Tutorial (C#)[
^],
System.Threading Namespace[
^].
And no,
it's useless to try to prepare to interviews and especially to look through some available interview answers and test problem solutions. You really want to
study the subject on regular basis and do
a lot of the real job to be ready to get hired. For some ideas, please see my past answer:
SSRS interview questions and answers[
^].
—SA