Click here to Skip to main content
15,927,344 members
Home / Discussions / C#
   

C#

 
GeneralRe: using this as synchronization object Pin
George_George22-Mar-08 4:03
George_George22-Mar-08 4:03 
GeneralRe: using this as synchronization object Pin
Colin Angus Mackay22-Mar-08 4:09
Colin Angus Mackay22-Mar-08 4:09 
GeneralRe: using this as synchronization object Pin
George_George23-Mar-08 2:53
George_George23-Mar-08 2:53 
GeneralRe: using this as synchronization object Pin
girm22-Mar-08 4:09
girm22-Mar-08 4:09 
GeneralRe: using this as synchronization object Pin
George_George23-Mar-08 2:54
George_George23-Mar-08 2:54 
GeneralRe: using this as synchronization object Pin
girm24-Mar-08 8:19
girm24-Mar-08 8:19 
GeneralRe: using this as synchronization object Pin
George_George24-Mar-08 19:01
George_George24-Mar-08 19:01 
GeneralRe: using this as synchronization object Pin
Colin Angus Mackay22-Mar-08 4:06
Colin Angus Mackay22-Mar-08 4:06 
If you are using the keyword "this" then most likely something elsewhere has access to that object, the thing that called the method you are in will have a reference to what ever "this" is, for example.

If you want to ensure that the object is threadsafe then exposing the thing you are using to lock (synchronise) isn't a good idea as code you have no control over could attempt to do the same thing by locking the object. If that happens, I'd imagine that it becomes easier to get into a situation where deadlocks can occur. A deadlock is where two bits of code are blocked because the first is waiting for the second to complete, and vice versa. In this scenario neither will complete.

So, if the object uses private objects internally to do the locking then nothing else can access the synchonisation objects and you have better control over how the locking works, and if you do find yourself in a situation where a deadlock occurs you won't have far to look to track down the problem (it will all be in one class).

Upcoming FREE developer events:
* Developer Day Scotland

Recent blog posts:
* Mixins in C#3.0

My website | Blog

GeneralRe: using this as synchronization object Pin
George_George23-Mar-08 2:51
George_George23-Mar-08 2:51 
GeneralRe: using this as synchronization object Pin
Colin Angus Mackay23-Mar-08 4:06
Colin Angus Mackay23-Mar-08 4:06 
GeneralRe: using this as synchronization object Pin
George_George23-Mar-08 4:17
George_George23-Mar-08 4:17 
QuestionHow do I create a subclass dynamically from a base class? [modified] Pin
loderxp22-Mar-08 2:57
loderxp22-Mar-08 2:57 
AnswerRe: How do I create a subclass dynamically from a base class? Pin
pmarfleet22-Mar-08 3:41
pmarfleet22-Mar-08 3:41 
Questionhow to search particular word Pin
sugunavathysubramanian22-Mar-08 1:04
sugunavathysubramanian22-Mar-08 1:04 
AnswerRe: how to search particular word Pin
Christian Graus22-Mar-08 11:43
protectorChristian Graus22-Mar-08 11:43 
GeneralRe: how to search particular word Pin
sugunavathysubramanian24-Mar-08 20:24
sugunavathysubramanian24-Mar-08 20:24 
GeneralRe: how to search particular word Pin
Christian Graus24-Mar-08 21:09
protectorChristian Graus24-Mar-08 21:09 
Generalsynchronization object choosing Pin
George_George22-Mar-08 0:36
George_George22-Mar-08 0:36 
GeneralRe: synchronization object choosing Pin
Colin Angus Mackay22-Mar-08 3:12
Colin Angus Mackay22-Mar-08 3:12 
GeneralRe: synchronization object choosing Pin
George_George22-Mar-08 3:28
George_George22-Mar-08 3:28 
GeneralRe: synchronization object choosing Pin
Colin Angus Mackay22-Mar-08 3:36
Colin Angus Mackay22-Mar-08 3:36 
GeneralRe: synchronization object choosing Pin
George_George22-Mar-08 3:39
George_George22-Mar-08 3:39 
Questionhow to use UltimateSearchInput in .net with c# Pin
sugunavathysubramanian21-Mar-08 23:53
sugunavathysubramanian21-Mar-08 23:53 
Questionnested lock? Pin
George_George21-Mar-08 23:10
George_George21-Mar-08 23:10 
AnswerRe: nested lock? Pin
Colin Angus Mackay21-Mar-08 23:49
Colin Angus Mackay21-Mar-08 23:49 

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.