473,466 Members | 1,413 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 2710
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: 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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.