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 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
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
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
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
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
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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:...
|
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
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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,...
| |