Click here to Skip to main content
15,913,467 members
Home / Discussions / C#
   

C#

 
GeneralRe: how to get the correct code Pin
Scott Dorman25-May-08 4:21
professionalScott Dorman25-May-08 4:21 
AnswerRe: how to get the correct code Pin
angels77725-May-08 4:20
angels77725-May-08 4:20 
GeneralRe: how to get the correct code Pin
Scott Dorman25-May-08 4:26
professionalScott Dorman25-May-08 4:26 
GeneralRe: how to get the correct code Pin
angels77725-May-08 5:00
angels77725-May-08 5:00 
GeneralRe: how to get the correct code Pin
Scott Dorman25-May-08 6:28
professionalScott Dorman25-May-08 6:28 
Questionwhich website??? pliz help me Pin
mbaz25-May-08 2:34
mbaz25-May-08 2:34 
AnswerRe: which website??? pliz help me Pin
Bert delaVega25-May-08 9:00
Bert delaVega25-May-08 9:00 
Questionlock needed in this scenario? Pin
George_George25-May-08 2:24
George_George25-May-08 2:24 
Hello everyone,


I have the following scenario, and my question is whether I need to add lock or not?

In my scenario, there are two threads, one thread is accessing Dictionary instance Dic1, and the other thread is creating new Dictionary instance regularly in some interval, and the new Dictionary instance is named Dic2, and this thread will assign the instance pointed by Dic1 to Dic2, so that the new produced Dic2 could be processed by the first thread.

(Dic1 is like data consumer, and Dic2 is like data producer.)

1.

My question is whether I need lock for the operation for Dic1 of thread1, and Dic2 to Dic1 assignment operation in thread 2?

2.

Beyond using lock, are there any more efficient method? e.g. less locking? or not using lock at all?

Some pesudo code,

// Thread 1
lock (Dic1) // lock for Dic1 instance needed here? This is my question
{
Dic1.op1();
Dic1.op2();
Dic1.op3();
} // end of lock


// Thread 2
Dictionary Dic2 = new Dictionary();
Dic2.insert();
Dic2.insert();
Dic2.insert();
lock (Dic1) // need lock here?
{
Dic1 = Dic2;
} // end of lock



thanks in advance,
George
AnswerRe: lock needed in this scenario? Pin
Anthony Mushrow25-May-08 3:11
professionalAnthony Mushrow25-May-08 3:11 
GeneralRe: lock needed in this scenario? Pin
George_George25-May-08 17:31
George_George25-May-08 17:31 
GeneralRe: lock needed in this scenario? Pin
Anthony Mushrow25-May-08 21:07
professionalAnthony Mushrow25-May-08 21:07 
GeneralRe: lock needed in this scenario? Pin
George_George25-May-08 21:28
George_George25-May-08 21:28 
AnswerRe: lock needed in this scenario? Pin
Luc Pattyn25-May-08 4:19
sitebuilderLuc Pattyn25-May-08 4:19 
GeneralRe: lock needed in this scenario? Pin
George_George25-May-08 18:53
George_George25-May-08 18:53 
GeneralRe: lock needed in this scenario? Pin
Luc Pattyn25-May-08 21:06
sitebuilderLuc Pattyn25-May-08 21:06 
GeneralRe: lock needed in this scenario? Pin
George_George25-May-08 21:27
George_George25-May-08 21:27 
GeneralRe: lock needed in this scenario? Pin
Luc Pattyn26-May-08 2:52
sitebuilderLuc Pattyn26-May-08 2:52 
GeneralRe: lock needed in this scenario? Pin
George_George26-May-08 15:39
George_George26-May-08 15:39 
Questiondoing validation in other file.cs Pin
angels77725-May-08 1:58
angels77725-May-08 1:58 
AnswerRe: doing validation in other file.cs Pin
Christian Graus25-May-08 2:03
protectorChristian Graus25-May-08 2:03 
GeneralRe: doing validation in other file.cs Pin
angels77725-May-08 2:10
angels77725-May-08 2:10 
GeneralRe: doing validation in other file.cs Pin
#realJSOP25-May-08 2:14
professional#realJSOP25-May-08 2:14 
Questionwhich website define proje from beginer to advance?, pliz help me Pin
mbaz25-May-08 1:56
mbaz25-May-08 1:56 
AnswerRe: which website define proje from beginer to advance?, pliz help me Pin
Christian Graus25-May-08 2:06
protectorChristian Graus25-May-08 2:06 
QuestionLine changment in streamWriter and sensitive replace method Pin
Casper Hansen25-May-08 1:53
Casper Hansen25-May-08 1:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.