473,320 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

I don't understand Synclock.

Specifically, I don't understand the parameter that Synclock accepts. How
is a reference type a lockable entity? What -is- a reference type? Is it a
number? Is it a value at a specific memory location? Does synclocking a
reference type put an entry in a catalog somewhere in the system, and it's
removed on the "end synclock" statement? Are there any guidelines for
creating synclock objects?

I've found a surprisingly small amount of information on the web. Everybody
just seems to know, or doesn't care, how Synclock works internally -- they
just create an Object and use it as Synclock's parameter. This is driving
me nuts! :)

--
Jeff S.
Nov 21 '05 #1
4 1950
Hi Jeff

Ref are memory locations on the heap. They are called ref types becuase unlike value types such as
simple primitives such integers,booleans,strucutres etc they are not assigned space on the Stack but
are merely "referred" to by pointer on the stack to some location on the heap.

SyncLocking in a very basic sense just protects an area in memory/stack/heap such that only the
thread that has the lock has access to that memory space.
I think of SyncLocks as basically a top down one at a time funnel or queue. Think of it as a
monogamous relationship - one at a time please - approach to
class useage... as opposed to non thread safe - dirty old skank - code that freely lets every man
and his dog have a crack at it as and when it pleases.

The latter approach leading to all forms of vile corruption.

hth
Richard
"Jeff Stewart" <ja*@micronovatech.com> wrote in message
news:1099953916.Fbdfx3mDVKhHNq5TeS3SAw@teranews...
Specifically, I don't understand the parameter that Synclock accepts. How
is a reference type a lockable entity? What -is- a reference type? Is it a
number? Is it a value at a specific memory location? Does synclocking a
reference type put an entry in a catalog somewhere in the system, and it's
removed on the "end synclock" statement? Are there any guidelines for
creating synclock objects?

I've found a surprisingly small amount of information on the web. Everybody
just seems to know, or doesn't care, how Synclock works internally -- they
just create an Object and use it as Synclock's parameter. This is driving
me nuts! :)

--
Jeff S.

Nov 21 '05 #2
:)

OK, but what decisions are made, internally, regarding the "lock"? What is
the mechanism by which the lock, or locked "thing" can affect whether
another thread can or cannot obtain the lock? When a lock is obtained by
one thread, how does a second thread reach the conclusion that a thread
other than itself "has the lock?"

--
Jeff S.
"Richard Myers" <fa**@address.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi Jeff

Ref are memory locations on the heap. They are called ref types becuase
unlike value types such as
simple primitives such integers,booleans,strucutres etc they are not
assigned space on the Stack but
are merely "referred" to by pointer on the stack to some location on the
heap.

SyncLocking in a very basic sense just protects an area in
memory/stack/heap such that only the
thread that has the lock has access to that memory space.
I think of SyncLocks as basically a top down one at a time funnel or
queue. Think of it as a
monogamous relationship - one at a time please - approach to
class useage... as opposed to non thread safe - dirty old skank - code
that freely lets every man
and his dog have a crack at it as and when it pleases.

The latter approach leading to all forms of vile corruption.

hth
Richard
"Jeff Stewart" <ja*@micronovatech.com> wrote in message
news:1099953916.Fbdfx3mDVKhHNq5TeS3SAw@teranews...
Specifically, I don't understand the parameter that Synclock accepts.
How
is a reference type a lockable entity? What -is- a reference type? Is
it a
number? Is it a value at a specific memory location? Does synclocking a
reference type put an entry in a catalog somewhere in the system, and
it's
removed on the "end synclock" statement? Are there any guidelines for
creating synclock objects?

I've found a surprisingly small amount of information on the web.
Everybody
just seems to know, or doesn't care, how Synclock works internally --
they
just create an Object and use it as Synclock's parameter. This is
driving
me nuts! :)

--
Jeff S.


Nov 21 '05 #3
Basically, this creates a Synchronization object. If you type Synclock
MyObject, MyObject becomes the key (probably creates something akin to a
Mutex internally).

Think of this as a gas station bathroom. The bathroom is the code inside the
Synclock block. Synclock is the station attendant, and the sync object you
provide is the key. The customers wanting to use the bathroom are the
different threads. The threads get to the synclock statement which is like
asking the attendant for the key, but if someone else already has the key,
the new customer has to wait to get into the bathroom until the customer who
has the key releases it back to the attendant - which is what happens when
the first thread reaches the End Synclock statement.

I've never actually researched what it "really" does internally, but my
guess is that it creates a sync wait object, like a Mutex. Any thread
executing the synclock statement is really trying to get exclusive access to
the wait object, and if the wait object has a previous ref count, the new
thread either spins until it can get the exclusive access, or it goes into a
wait state until the wait object signals that it's free. Either way, the end
result is pretty much the same - only one thread at a time can have
exclusive access to the wait object.

-Rob Teixeira

"Jeff Stewart" <ja*@micronovatech.com> wrote in message
news:1099959308.PUM15gOliewqRbiF6R5yFg@teranews...
:)

OK, but what decisions are made, internally, regarding the "lock"? What is the mechanism by which the lock, or locked "thing" can affect whether
another thread can or cannot obtain the lock? When a lock is obtained by
one thread, how does a second thread reach the conclusion that a thread
other than itself "has the lock?"

--
Jeff S.
"Richard Myers" <fa**@address.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi Jeff

Ref are memory locations on the heap. They are called ref types becuase
unlike value types such as
simple primitives such integers,booleans,strucutres etc they are not
assigned space on the Stack but
are merely "referred" to by pointer on the stack to some location on the
heap.

SyncLocking in a very basic sense just protects an area in
memory/stack/heap such that only the
thread that has the lock has access to that memory space.
I think of SyncLocks as basically a top down one at a time funnel or
queue. Think of it as a
monogamous relationship - one at a time please - approach to
class useage... as opposed to non thread safe - dirty old skank - code
that freely lets every man
and his dog have a crack at it as and when it pleases.

The latter approach leading to all forms of vile corruption.

hth
Richard
"Jeff Stewart" <ja*@micronovatech.com> wrote in message
news:1099953916.Fbdfx3mDVKhHNq5TeS3SAw@teranews...
Specifically, I don't understand the parameter that Synclock accepts.
How
is a reference type a lockable entity? What -is- a reference type? Is
it a
number? Is it a value at a specific memory location? Does synclocking a reference type put an entry in a catalog somewhere in the system, and
it's
removed on the "end synclock" statement? Are there any guidelines for
creating synclock objects?

I've found a surprisingly small amount of information on the web.
Everybody
just seems to know, or doesn't care, how Synclock works internally --
they
just create an Object and use it as Synclock's parameter. This is
driving
me nuts! :)

--
Jeff S.



Nov 21 '05 #4
Hi Jeff

The lock is just a token;this can be anything;when you create a lock you define a token;if the token
is used/in possesion of another thread then it blocks other threads from taking ownership of the
token.

If your talking about the really low level implementation of this feature then im not entirely sure
as one of the great things about OOP is its' black box nature.

I would assume the "token" is just given a memory space as usual and to which a secondary pointer
is appended under the covers. This pointer would then poiint at the owner of the token or be null.
If a thread tries to access a token which has a pointer that is not null or pointing to itself then
it is blocked? If the pointer is free; the thread regsiters itself such that the pointer address
points back to the registering thread so if other threads try to gain access they are blocked.

When then thread is done (EndSynclock) it releases the token by setting the pointer to null so other
threads can have a crack at it. In this way the synch lock is kinda like a box. Inside the box is
whatever Synchlock is protecting plus a pointer to whoever owns the box at that particular moment.

Chances are this is completely wrong, its an interesting question but i haven't really thought about
the precise mechanism it uses- Im an applications developer not a systems developer so i prefer to
spend more time listening to the customer than worrying about the way windows/clr shunts its bits
and bytes around. I suppose i should know but the truth is Im not absolutely certain?

Richard
"Jeff Stewart" <ja*@micronovatech.com> wrote in message
news:1099959308.PUM15gOliewqRbiF6R5yFg@teranews...
:)

OK, but what decisions are made, internally, regarding the "lock"? What is
the mechanism by which the lock, or locked "thing" can affect whether
another thread can or cannot obtain the lock? When a lock is obtained by
one thread, how does a second thread reach the conclusion that a thread
other than itself "has the lock?"
sure
--
Jeff S.
"Richard Myers" <fa**@address.com> wrote in message realses the token and
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi Jeff

Ref are memory locations on the heap. They are called ref types becuase
unlike value types such as
simple primitives such integers,booleans,strucutres etc they are not
assigned space on the Stack but
are merely "referred" to by pointer on the stack to some location on the
heap.

SyncLocking in a very basic sense just protects an area in
memory/stack/heap such that only the
thread that has the lock has access to that memory space.
I think of SyncLocks as basically a top down one at a time funnel or
queue. Think of it as a
monogamous relationship - one at a time please - approach to
class useage... as opposed to non thread safe - dirty old skank - code
that freely lets every man
and his dog have a crack at it as and when it pleases.

The latter approach leading to all forms of vile corruption.

hth
Richard
"Jeff Stewart" <ja*@micronovatech.com> wrote in message
news:1099953916.Fbdfx3mDVKhHNq5TeS3SAw@teranews...
Specifically, I don't understand the parameter that Synclock accepts.
How
is a reference type a lockable entity? What -is- a reference type? Is
it a
number? Is it a value at a specific memory location? Does synclocking a
reference type put an entry in a catalog somewhere in the system, and
it's
removed on the "end synclock" statement? Are there any guidelines for
creating synclock objects?

I've found a surprisingly small amount of information on the web.
Everybody
just seems to know, or doesn't care, how Synclock works internally --
they
just create an Object and use it as Synclock's parameter. This is
driving
me nuts! :)

--
Jeff S.



Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ram | last post by:
Hey, I have about 5 Shared variables, that I want to be locked for access when they are written to. I'v read in the MSDN about the SyncLock statement, and I'm prety sure that's what I'm looking...
0
by: Nashat Wanly | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaskdr/html/askgui06032003.asp Don't Lock Type Objects! Why Lock(typeof(ClassName)) or SyncLock GetType(ClassName) Is Bad Rico...
3
by: Ram | last post by:
Hey, I have about 5 Shared variables, that I want to be locked for access when they are written to. I'v read in the MSDN about the SyncLock statement, and I'm prety sure that's what I'm looking...
7
by: SD | last post by:
I have a public object that I only want one thread to access at a time. However the access to this object is not limited to one procedure. Will SyncLock work in this case? If not what options do I...
1
by: fred | last post by:
I have a VB application that is using MS Access as its database. To avoid connection delays the application creates one connection to the database at start-up and maintains that single connection...
3
by: Chris Dunaway | last post by:
I was using a Queue object like this to create my own specialized queue class for use with my own objects: Public Class MySpecializedQueue Private q As New Queue Public Sub Enqueue(obj As...
13
by: cj | last post by:
Stephany Young provided me with the following code to count threads created by my program. Public Class MyThreadCount Private Shared m_lock As New Object Private Shared m_threadcount As Int32...
2
by: HONOREDANCESTOR | last post by:
I have a buffer that needs to be locked sometimes, because 2 processes update it. So I made the buffer into a class and whenever there is code that affects it, I sandwich the code between ...
10
by: Frank Osterberg | last post by:
Hi, I want to simultaneously SyncLock multiple objects, something like: SyncLock objA, objB ' do stuff with objA and objB
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.