ExDeleteResourceLite

What happens when I ExDeleteResourceLite while some other threads acquired
resource or waiting for acquirement. I implemented resource synchronization
object in user mode. Don’t know only what special processing I have to do in
my DeleteResource routine.

You have to make sure that the resource has been released and ensure that
its never acquired again before deleting it. Otherwise you will have threads
waiting on the resource object (not exactly accurate) and if you delete it
you will have stale pointers that can cause bugchecks.


Nar Ganapathy
Windows Core OS group
This posting is provided “AS IS” with no warranties, and confers no rights.
“Alexey Logachyov” wrote in message news:xxxxx@ntdev…
>
> What happens when I ExDeleteResourceLite while some other threads acquired
> resource or waiting for acquirement. I implemented resource
synchronization
> object in user mode. Don’t know only what special processing I have to do
in
> my DeleteResource routine.
>
>
>
>
>

So, it should be completely safe to delete resource object when it is
acquired. Am I right? What happens if a thread owning a resource is
terminated. Will resouce be released correctly?

And another question. What is exact behaviour of
ExAcquireSharedWaitForExclusiveLite function? DDK information is poor on the
subject.

----- Original Message -----
From: “Nar Ganapathy [MS]”
Newsgroups: ntdev
To: “NT Developers Interest List”
Sent: Thursday, July 18, 2002 11:06 PM
Subject: [ntdev] Re: ExDeleteResourceLite

> You have to make sure that the resource has been released and ensure that
> its never acquired again before deleting it. Otherwise you will have
threads
> waiting on the resource object (not exactly accurate) and if you delete it
> you will have stale pointers that can cause bugchecks.
>
> –
> Nar Ganapathy
> Windows Core OS group
> This posting is provided “AS IS” with no warranties, and confers no
rights.
> “Alexey Logachyov” wrote in message news:xxxxx@ntdev…
> >
> > What happens when I ExDeleteResourceLite while some other threads
acquired
> > resource or waiting for acquirement. I implemented resource
> synchronization
> > object in user mode. Don’t know only what special processing I have to
do
> in
> > my DeleteResource routine.
> >
> >
> >
> >
> >
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@vba.com.by
> To unsubscribe send a blank email to %%email.unsub%%
>

>> So, it should be completely safe to delete resource object when it is
acquired

Nope it wont.

> ExAcquireSharedWaitForExclusiveLite

The DDK docs from build 2600 of DDK documents it preety well.

----- Original Message -----
From: “Alexey Logachyov”
To: “NT Developers Interest List”
Sent: Thursday, July 18, 2002 11:33 PM
Subject: [ntdev] Re: ExDeleteResourceLite

> So, it should be completely safe to delete resource object when it is
> acquired. Am I right? What happens if a thread owning a resource is
> terminated. Will resouce be released correctly?
>
> And another question. What is exact behaviour of
> ExAcquireSharedWaitForExclusiveLite function? DDK information is poor on
the
> subject.
>
> ----- Original Message -----
> From: “Nar Ganapathy [MS]”
> Newsgroups: ntdev
> To: “NT Developers Interest List”
> Sent: Thursday, July 18, 2002 11:06 PM
> Subject: [ntdev] Re: ExDeleteResourceLite
>
>
> > You have to make sure that the resource has been released and ensure
that
> > its never acquired again before deleting it. Otherwise you will have
> threads
> > waiting on the resource object (not exactly accurate) and if you delete
it
> > you will have stale pointers that can cause bugchecks.
> >
> > –
> > Nar Ganapathy
> > Windows Core OS group
> > This posting is provided “AS IS” with no warranties, and confers no
> rights.
> > “Alexey Logachyov” wrote in message
news:xxxxx@ntdev…
> > >
> > > What happens when I ExDeleteResourceLite while some other threads
> acquired
> > > resource or waiting for acquirement. I implemented resource
> > synchronization
> > > object in user mode. Don’t know only what special processing I have to
> do
> > in
> > > my DeleteResource routine.
> > >
> > >
> > >
> > >
> > >
> >
> >
> >
> > —
> > You are currently subscribed to ntdev as: xxxxx@vba.com.by
> > To unsubscribe send a blank email to %%email.unsub%%
> >
>
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@rdsor.ro
> To unsubscribe send a blank email to %%email.unsub%%
>

>> So, it should be completely safe to delete resource object when it is

> acquired
Nope it wont.
Sorry, I was not attentive to words.

> ExAcquireSharedWaitForExclusiveLite
The DDK docs from build 2600 of DDK documents it preety well.
Here’s a piece from DDK:
– If the resource is currently unowned, shared access is granted
immediately to the current thread.
– If the caller already has exclusive access to the resource, the current
thread is granted the same type of access recursively.
– If the resource is currently owned as shared and there are no pending
attempts to acquire exclusive access, shared access is granted to the caller
immediately.
– If the resource is currently owned as shared but there is a pending
attempt to acquire exclusive access, the caller either is put into a wait
state (Wait set to TRUE) or ExAcquireSharedWaitForExclusive returns FALSE.

Imagine the next scenario:
– Thread A acquires resource for shared access.
– Thread B tries to acquire resource exclusively and blocks waiting for
access.
– Thread A tries to acquire the same resource for shared access. According
to docs “if the resource is currently owned as shared but there is a pending
attempt to acquire exclusive access, the caller either is put into a wait
state”. So, it’s a deadlock!

Docs for ExAcquireResourceSharedLite in second statement say explicitely:
"if the caller already has acquired the resource (for *shared or exclusive*
access), while docs for ExAcquireSharedWaitForExclusive say “if the caller
already has exclusive access to the resource”.

Please, explain.

----- Original Message -----
From: “Alexey Logachyov”
> To: “NT Developers Interest List”
> Sent: Thursday, July 18, 2002 11:33 PM
> Subject: [ntdev] Re: ExDeleteResourceLite
>
>
> > So, it should be completely safe to delete resource object when it is
> > acquired. Am I right? What happens if a thread owning a resource is
> > terminated. Will resouce be released correctly?
> >
> > And another question. What is exact behaviour of
> > ExAcquireSharedWaitForExclusiveLite function? DDK information is poor on
> the
> > subject.
> >
> > ----- Original Message -----
> > From: “Nar Ganapathy [MS]”
> > Newsgroups: ntdev
> > To: “NT Developers Interest List”
> > Sent: Thursday, July 18, 2002 11:06 PM
> > Subject: [ntdev] Re: ExDeleteResourceLite
> >
> >
> > > You have to make sure that the resource has been released and ensure
> that
> > > its never acquired again before deleting it. Otherwise you will have
> > threads
> > > waiting on the resource object (not exactly accurate) and if you
delete
> it
> > > you will have stale pointers that can cause bugchecks.
> > >
> > > –
> > > Nar Ganapathy
> > > Windows Core OS group
> > > This posting is provided “AS IS” with no warranties, and confers no
> > rights.
> > > “Alexey Logachyov” wrote in message
> news:xxxxx@ntdev…
> > > >
> > > > What happens when I ExDeleteResourceLite while some other threads
> > acquired
> > > > resource or waiting for acquirement. I implemented resource
> > > synchronization
> > > > object in user mode. Don’t know only what special processing I have
to
> > do
> > > in
> > > > my DeleteResource routine.
> > > >
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> > >
> > > —
> > > You are currently subscribed to ntdev as: xxxxx@vba.com.by
> > > To unsubscribe send a blank email to %%email.unsub%%
> > >
> >
> >
> >
> >
> > —
> > You are currently subscribed to ntdev as: xxxxx@rdsor.ro
> > To unsubscribe send a blank email to %%email.unsub%%
> >
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@vba.com.by
> To unsubscribe send a blank email to %%email.unsub%%
>

Whether it’s a deadlock or not depends on which of the three shared
acquire APIs you call in step 3 of your “next scenario”:
. ExAcquireSharedWaitForExclusive -
Yes this will deadlock thread A. This doesn’t care if A already owns it
shared - if there’s an exclusive waiter, it gives him priority.

. ExAcquireResourceSharedLite - No deadlock. This will let A go
through if he already has shared access

. ExAcquireSharedStarveExclusive - No deadlock. This lets shared
waiters go through even if there are *other* exclusive waiters.

Ravi

This posting is provided “AS IS” with no warranties, and confers no
rights.

-----Original Message-----
From: Alexey Logachyov [mailto:xxxxx@vba.com.by]
Sent: Friday, July 19, 2002 9:35 AM
To: NT Developers Interest List
Subject: [ntdev] Re: ExDeleteResourceLite

> So, it should be completely safe to delete resource object when it is
> acquired
Nope it wont.
Sorry, I was not attentive to words.

> ExAcquireSharedWaitForExclusiveLite
The DDK docs from build 2600 of DDK documents it preety well.
Here’s a piece from DDK:
– If the resource is currently unowned, shared access is granted
immediately to the current thread.
– If the caller already has exclusive access to the resource, the
current thread is granted the same type of access recursively.
– If the resource is currently owned as shared and there are no pending
attempts to acquire exclusive access, shared access is granted to the
caller immediately.
– If the resource is currently owned as shared but there is a pending
attempt to acquire exclusive access, the caller either is put into a
wait state (Wait set to TRUE) or ExAcquireSharedWaitForExclusive returns
FALSE.

Imagine the next scenario:
– Thread A acquires resource for shared access.
– Thread B tries to acquire resource exclusively and blocks waiting for
access.
– Thread A tries to acquire the same resource for shared access.
According to docs “if the resource is currently owned as shared but
there is a pending attempt to acquire exclusive access, the caller
either is put into a wait state”. So, it’s a deadlock!

Docs for ExAcquireResourceSharedLite in second statement say
explicitely: "if the caller already has acquired the resource (for
*shared or exclusive* access), while docs for
ExAcquireSharedWaitForExclusive say “if the caller already has exclusive
access to the resource”.

Please, explain.

----- Original Message -----
From: “Alexey Logachyov”
> To: “NT Developers Interest List”
> Sent: Thursday, July 18, 2002 11:33 PM
> Subject: [ntdev] Re: ExDeleteResourceLite
>
>
> > So, it should be completely safe to delete resource object when it
> > is acquired. Am I right? What happens if a thread owning a resource
> > is terminated. Will resouce be released correctly?
> >
> > And another question. What is exact behaviour of
> > ExAcquireSharedWaitForExclusiveLite function? DDK information is
> > poor on
> the
> > subject.
> >
> > ----- Original Message -----
> > From: “Nar Ganapathy [MS]”
> > Newsgroups: ntdev
> > To: “NT Developers Interest List”
> > Sent: Thursday, July 18, 2002 11:06 PM
> > Subject: [ntdev] Re: ExDeleteResourceLite
> >
> >
> > > You have to make sure that the resource has been released and
> > > ensure
> that
> > > its never acquired again before deleting it. Otherwise you will
> > > have
> > threads
> > > waiting on the resource object (not exactly accurate) and if you
delete
> it
> > > you will have stale pointers that can cause bugchecks.
> > >
> > > –
> > > Nar Ganapathy
> > > Windows Core OS group
> > > This posting is provided “AS IS” with no warranties, and confers
> > > no
> > rights.
> > > “Alexey Logachyov” wrote in message
> news:xxxxx@ntdev…
> > > >
> > > > What happens when I ExDeleteResourceLite while some other
> > > > threads
> > acquired
> > > > resource or waiting for acquirement. I implemented resource
> > > synchronization
> > > > object in user mode. Don’t know only what special processing I
> > > > have
to
> > do
> > > in
> > > > my DeleteResource routine.
> > > >
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> > >
> > > —
> > > You are currently subscribed to ntdev as: xxxxx@vba.com.by To
> > > unsubscribe send a blank email to %%email.unsub%%
> > >
> >
> >
> >
> >
> > —
> > You are currently subscribed to ntdev as: xxxxx@rdsor.ro To
> > unsubscribe send a blank email to %%email.unsub%%
> >
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@vba.com.by
> To unsubscribe send a blank email to %%email.unsub%%
>


You are currently subscribed to ntdev as: xxxxx@microsoft.com To
unsubscribe send a blank email to %%email.unsub%%

> Whether it’s a deadlock or not depends on which of the three shared

acquire APIs you call in step 3 of your “next scenario”:
. ExAcquireSharedWaitForExclusive -
Yes this will deadlock thread A. This doesn’t care if A already owns it
shared - if there’s an exclusive waiter, it gives him priority.
I was about this routine. So, it seems that ExAcquireSharedWaitForExclusive
is not safe to use. Assuming that ExAcquireResourceSharedLite lacks for this
problem (gives way to exclusive waiters but do not deadlock when acquiring
recursively), ExAcquireSharedWaitForExclusive has no use. Am I right?

As I understand it , your scenario is dependant of the Wait parameter set to
TRUE.

If the resource is acquired shared && the number of exclusive waiters > 0 &&
Wait is FALSE, recursive Shared access will not be granted. The routine will
return FALSE, and soon as possible exclusive access will be granted to the
first thread which demanded it.

I think the routine is safe to be used. Its your duty as a programmer to
prevent deadlocks.

Dan

----- Original Message -----
From: “Alexey Logachyov”
To: “NT Developers Interest List”
Sent: Friday, July 19, 2002 7:34 PM
Subject: [ntdev] Re: ExDeleteResourceLite

> >> So, it should be completely safe to delete resource object when it is
> >> acquired
> > Nope it wont.
> Sorry, I was not attentive to words.
>
> >> ExAcquireSharedWaitForExclusiveLite
> > The DDK docs from build 2600 of DDK documents it preety well.
> Here’s a piece from DDK:
> – If the resource is currently unowned, shared access is granted
> immediately to the current thread.
> – If the caller already has exclusive access to the resource, the current
> thread is granted the same type of access recursively.
> – If the resource is currently owned as shared and there are no pending
> attempts to acquire exclusive access, shared access is granted to the
caller
> immediately.
> – If the resource is currently owned as shared but there is a pending
> attempt to acquire exclusive access, the caller either is put into a wait
> state (Wait set to TRUE) or ExAcquireSharedWaitForExclusive returns FALSE.
>
> Imagine the next scenario:
> – Thread A acquires resource for shared access.
> – Thread B tries to acquire resource exclusively and blocks waiting for
> access.
> – Thread A tries to acquire the same resource for shared access.
According
> to docs “if the resource is currently owned as shared but there is a
pending
> attempt to acquire exclusive access, the caller either is put into a wait
> state”. So, it’s a deadlock!
>
> Docs for ExAcquireResourceSharedLite in second statement say explicitely:
> "if the caller already has acquired the resource (for shared or
exclusive

> access), while docs for ExAcquireSharedWaitForExclusive say “if the caller
> already has exclusive access to the resource”.
>
> Please, explain.
>
> > ----- Original Message -----
> > From: “Alexey Logachyov”
> > To: “NT Developers Interest List”
> > Sent: Thursday, July 18, 2002 11:33 PM
> > Subject: [ntdev] Re: ExDeleteResourceLite
> >
> >
> > > So, it should be completely safe to delete resource object when it is
> > > acquired. Am I right? What happens if a thread owning a resource is
> > > terminated. Will resouce be released correctly?
> > >
> > > And another question. What is exact behaviour of
> > > ExAcquireSharedWaitForExclusiveLite function? DDK information is poor
on
> > the
> > > subject.
> > >
> > > ----- Original Message -----
> > > From: “Nar Ganapathy [MS]”
> > > Newsgroups: ntdev
> > > To: “NT Developers Interest List”
> > > Sent: Thursday, July 18, 2002 11:06 PM
> > > Subject: [ntdev] Re: ExDeleteResourceLite
> > >
> > >
> > > > You have to make sure that the resource has been released and ensure
> > that
> > > > its never acquired again before deleting it. Otherwise you will have
> > > threads
> > > > waiting on the resource object (not exactly accurate) and if you
> delete
> > it
> > > > you will have stale pointers that can cause bugchecks.
> > > >
> > > > –
> > > > Nar Ganapathy
> > > > Windows Core OS group
> > > > This posting is provided “AS IS” with no warranties, and confers no
> > > rights.
> > > > “Alexey Logachyov” wrote in message
> > news:xxxxx@ntdev…
> > > > >
> > > > > What happens when I ExDeleteResourceLite while some other threads
> > > acquired
> > > > > resource or waiting for acquirement. I implemented resource
> > > > synchronization
> > > > > object in user mode. Don’t know only what special processing I
have
> to
> > > do
> > > > in
> > > > > my DeleteResource routine.
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > > >
> > > > —
> > > > You are currently subscribed to ntdev as: xxxxx@vba.com.by
> > > > To unsubscribe send a blank email to %%email.unsub%%
> > > >
> > >
> > >
> > >
> > >
> > > —
> > > You are currently subscribed to ntdev as: xxxxx@rdsor.ro
> > > To unsubscribe send a blank email to %%email.unsub%%
> > >
> >
> >
> >
> > —
> > You are currently subscribed to ntdev as: xxxxx@vba.com.by
> > To unsubscribe send a blank email to %%email.unsub%%
> >
>
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@rdsor.ro
> To unsubscribe send a blank email to %%email.unsub%%
>