473,387 Members | 1,925 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,387 software developers and data experts.

Synclock clarification

Hi all!

I just need a true or false answer for this statement.
Consider having a piece of code that boils down to this

Dim a = new ArrayList
SyncLock a
SyncLock a
a.Add("Something")
End SyncLock
End SyncLock

The question: Since it is the same thread that locks the resource twice the
add function will execute without problems, right? And other threads trying
to lock will just have to wait 'til their turn?

Another question while im at it: If all lockings withing an assembly only
refer to a single object, that is there is not "nested" locking, a deadlock
can never occour? Right or wrong? Need some more clarification? :)

Thanks!

/Johan
Nov 20 '05 #1
6 2704
True and yes there can be deadlocks still if you have more than one thread
and more than one lockable resource.
"Johan Karlsson" <jo************@adnome.se> wrote in message
news:u1**************@TK2MSFTNGP10.phx.gbl...
Hi all!

I just need a true or false answer for this statement.
Consider having a piece of code that boils down to this

Dim a = new ArrayList
SyncLock a
SyncLock a
a.Add("Something")
End SyncLock
End SyncLock

The question: Since it is the same thread that locks the resource twice the add function will execute without problems, right? And other threads trying to lock will just have to wait 'til their turn?

Another question while im at it: If all lockings withing an assembly only
refer to a single object, that is there is not "nested" locking, a deadlock can never occour? Right or wrong? Need some more clarification? :)

Thanks!

/Johan

Nov 20 '05 #2
True and yes there can be deadlocks still if you have more than one thread
and more than one lockable resource.
"Johan Karlsson" <jo************@adnome.se> wrote in message
news:u1**************@TK2MSFTNGP10.phx.gbl...
Hi all!

I just need a true or false answer for this statement.
Consider having a piece of code that boils down to this

Dim a = new ArrayList
SyncLock a
SyncLock a
a.Add("Something")
End SyncLock
End SyncLock

The question: Since it is the same thread that locks the resource twice the add function will execute without problems, right? And other threads trying to lock will just have to wait 'til their turn?

Another question while im at it: If all lockings withing an assembly only
refer to a single object, that is there is not "nested" locking, a deadlock can never occour? Right or wrong? Need some more clarification? :)

Thanks!

/Johan

Nov 20 '05 #3
Hi and thank you for the reply!
On the second question,

Could you explain to me how that deadlock would occure. That is, there is no
code that will lock two object within the same thread. Example, thread tA
will never lock object oA and oB at the same time, it will first lock oA, do
its business and then lock (and release oA) object oB. Thread tB will have
the same "rules" and never lock oA and oB at the same time.

I just cant figure out how a deadlock can occure then? But I'm kindofa
newbie in the threadworld.

Thanks

/Johan
"drew" <me@here.com> wrote in message
news:uq**************@TK2MSFTNGP11.phx.gbl...
True and yes there can be deadlocks still if you have more than one thread
and more than one lockable resource.
"Johan Karlsson" <jo************@adnome.se> wrote in message
news:u1**************@TK2MSFTNGP10.phx.gbl...
Hi all!

I just need a true or false answer for this statement.
Consider having a piece of code that boils down to this

Dim a = new ArrayList
SyncLock a
SyncLock a
a.Add("Something")
End SyncLock
End SyncLock

The question: Since it is the same thread that locks the resource twice

the
add function will execute without problems, right? And other threads

trying
to lock will just have to wait 'til their turn?

Another question while im at it: If all lockings withing an assembly only refer to a single object, that is there is not "nested" locking, a

deadlock
can never occour? Right or wrong? Need some more clarification? :)

Thanks!

/Johan


Nov 20 '05 #4
Hi and thank you for the reply!
On the second question,

Could you explain to me how that deadlock would occure. That is, there is no
code that will lock two object within the same thread. Example, thread tA
will never lock object oA and oB at the same time, it will first lock oA, do
its business and then lock (and release oA) object oB. Thread tB will have
the same "rules" and never lock oA and oB at the same time.

I just cant figure out how a deadlock can occure then? But I'm kindofa
newbie in the threadworld.

Thanks

/Johan
"drew" <me@here.com> wrote in message
news:uq**************@TK2MSFTNGP11.phx.gbl...
True and yes there can be deadlocks still if you have more than one thread
and more than one lockable resource.
"Johan Karlsson" <jo************@adnome.se> wrote in message
news:u1**************@TK2MSFTNGP10.phx.gbl...
Hi all!

I just need a true or false answer for this statement.
Consider having a piece of code that boils down to this

Dim a = new ArrayList
SyncLock a
SyncLock a
a.Add("Something")
End SyncLock
End SyncLock

The question: Since it is the same thread that locks the resource twice

the
add function will execute without problems, right? And other threads

trying
to lock will just have to wait 'til their turn?

Another question while im at it: If all lockings withing an assembly only refer to a single object, that is there is not "nested" locking, a

deadlock
can never occour? Right or wrong? Need some more clarification? :)

Thanks!

/Johan


Nov 20 '05 #5
You're correct in your assumption; as long as you code carefully and make
sure that you always release the first object before trying to acquire the
second object you should never have any deadlocks. You'll also want to make
sure you have finally's around to release the locks as well... with
threading always land on the carefull side.

drew
"Johan Karlsson" <jo************@adnome.se> wrote in message
news:uI**************@tk2msftngp13.phx.gbl...
Hi and thank you for the reply!
On the second question,

Could you explain to me how that deadlock would occure. That is, there is no code that will lock two object within the same thread. Example, thread tA
will never lock object oA and oB at the same time, it will first lock oA, do its business and then lock (and release oA) object oB. Thread tB will have
the same "rules" and never lock oA and oB at the same time.

I just cant figure out how a deadlock can occure then? But I'm kindofa
newbie in the threadworld.

Thanks

/Johan
"drew" <me@here.com> wrote in message
news:uq**************@TK2MSFTNGP11.phx.gbl...
True and yes there can be deadlocks still if you have more than one thread
and more than one lockable resource.
"Johan Karlsson" <jo************@adnome.se> wrote in message
news:u1**************@TK2MSFTNGP10.phx.gbl...
Hi all!

I just need a true or false answer for this statement.
Consider having a piece of code that boils down to this

Dim a = new ArrayList
SyncLock a
SyncLock a
a.Add("Something")
End SyncLock
End SyncLock

The question: Since it is the same thread that locks the resource
twice the
add function will execute without problems, right? And other threads

trying
to lock will just have to wait 'til their turn?

Another question while im at it: If all lockings withing an assembly

only refer to a single object, that is there is not "nested" locking, a

deadlock
can never occour? Right or wrong? Need some more clarification? :)

Thanks!

/Johan



Nov 20 '05 #6
You're correct in your assumption; as long as you code carefully and make
sure that you always release the first object before trying to acquire the
second object you should never have any deadlocks. You'll also want to make
sure you have finally's around to release the locks as well... with
threading always land on the carefull side.

drew
"Johan Karlsson" <jo************@adnome.se> wrote in message
news:uI**************@tk2msftngp13.phx.gbl...
Hi and thank you for the reply!
On the second question,

Could you explain to me how that deadlock would occure. That is, there is no code that will lock two object within the same thread. Example, thread tA
will never lock object oA and oB at the same time, it will first lock oA, do its business and then lock (and release oA) object oB. Thread tB will have
the same "rules" and never lock oA and oB at the same time.

I just cant figure out how a deadlock can occure then? But I'm kindofa
newbie in the threadworld.

Thanks

/Johan
"drew" <me@here.com> wrote in message
news:uq**************@TK2MSFTNGP11.phx.gbl...
True and yes there can be deadlocks still if you have more than one thread
and more than one lockable resource.
"Johan Karlsson" <jo************@adnome.se> wrote in message
news:u1**************@TK2MSFTNGP10.phx.gbl...
Hi all!

I just need a true or false answer for this statement.
Consider having a piece of code that boils down to this

Dim a = new ArrayList
SyncLock a
SyncLock a
a.Add("Something")
End SyncLock
End SyncLock

The question: Since it is the same thread that locks the resource
twice the
add function will execute without problems, right? And other threads

trying
to lock will just have to wait 'til their turn?

Another question while im at it: If all lockings withing an assembly

only refer to a single object, that is there is not "nested" locking, a

deadlock
can never occour? Right or wrong? Need some more clarification? :)

Thanks!

/Johan



Nov 20 '05 #7

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

Similar topics

4
by: fred | last post by:
If I have multiple threads running a Sub as below then a number of threads can be held up at the SyncLock. When it becomes free which thread goes first. Is it just by chance which thread goes first...
10
by: Bob Day | last post by:
Using vs 2003, vb.net sql msde.. Consider the following code snippets. See **** for questions. All are shared and accessed by multiple threads simultaneiously. ' Instantiate per for this...
3
by: Bob Day | last post by:
Ok, I have done a lot of reading(of the newsgroup answers, help files and MSDN articles) of synclock. I understand what you are saying in the newsgroup, and it is very helpful. It does, however,...
0
by: Johan Karlsson | last post by:
Hi all! I just need a true or false answer for this statement. Consider having a piece of code that boils down to this Dim a = new ArrayList SyncLock a SyncLock a a.Add("Something") End...
4
by: Jeff Stewart | last post by:
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...
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...
2
by: j3ko | last post by:
Hi, I'm trying to start a thread that constantly iterates through an arraylist of items that the main thread adds and removes from...how would I accomplish this? Here's the gist of what I have:...
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 ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.