Sharing stack-allocated data between threads

Hi everyone!

It’s a kind of paranoid question, but can I share stack-allocated data
between different threads?
I mean can thread stack be viewed as “just another pool” of memory that is
available from all other
threads?

Sorry, I guess it’s been too much of work and beer yesterday :slight_smile:

TIA,

Vladimir

I’m assuming you’re refering to user-mode.

Since all memory in a process is shared between all threads of that process, the stacks all share the same process memory so you can “get at” other threads’ memory. However, there is the obvious problem that if a function returns all its stack data is invalidated and be overwritten by the next stack usage. So, the answer is “yes, if you’re very careful”.

Regards

Paul Bunn, UltraBac Software, 425-644-6000
Microsoft MVP - NT/Windows 2000/XP
http://www.ultrabac.com

-----Original Message-----
From: Chtchetkine, Vladimir [mailto:xxxxx@starbase.com]
Sent: Thursday, May 02, 2002 7:23 AM
To: NT Developers Interest List
Subject: [ntdev] Sharing stack-allocated data between threads

Hi everyone!
It’s a kind of paranoid question, but can I share stack-allocated data between different threads?
I mean can thread stack be viewed as “just another pool” of memory that is available from all other
threads?
Sorry, I guess it’s been too much of work and beer yesterday :slight_smile:

Nope! I’m refering to KM thread stack.

-----Original Message-----
From: Paul Bunn [mailto:xxxxx@UltraBac.com]
Sent: Thursday, May 02, 2002 8:54 AM
To: NT Developers Interest List
Subject: [ntdev] RE: Sharing stack-allocated data between threads

I’m assuming you’re refering to user-mode.

Since all memory in a process is shared between all threads of that process,
the stacks all share the same process memory so you can “get at” other
threads’ memory. However, there is the obvious problem that if a function
returns all its stack data is invalidated and be overwritten by the next
stack usage. So, the answer is “yes, if you’re very careful”.

Regards

Paul Bunn, UltraBac Software, 425-644-6000
Microsoft MVP - NT/Windows 2000/XP
http://www.ultrabac.com

-----Original Message-----
From: Chtchetkine, Vladimir [mailto:xxxxx@starbase.com]
Sent: Thursday, May 02, 2002 7:23 AM
To: NT Developers Interest List
Subject: [ntdev] Sharing stack-allocated data between threads

Hi everyone!
It’s a kind of paranoid question, but can I share stack-allocated data
between different threads?
I mean can thread stack be viewed as “just another pool” of memory that is
available from all other
threads?
Sorry, I guess it’s been too much of work and beer yesterday :slight_smile:


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

RE: [ntdev] RE: Sharing stack-allocated data between threadsNo, You cannot - I am sure, u will screw me, if u use my thread stack :slight_smile:

----- Original Message -----
From: Chtchetkine, Vladimir
To: NT Developers Interest List
Sent: Thursday, May 02, 2002 9:46 PM
Subject: [ntdev] RE: Sharing stack-allocated data between threads

Nope! I’m refering to KM thread stack.

-----Original Message-----
From: Paul Bunn [mailto:xxxxx@UltraBac.com]
Sent: Thursday, May 02, 2002 8:54 AM
To: NT Developers Interest List
Subject: [ntdev] RE: Sharing stack-allocated data between threads

I’m assuming you’re refering to user-mode.

Since all memory in a process is shared between all threads of that process, the stacks all share the same process memory so you can “get at” other threads’ memory. However, there is the obvious problem that if a function returns all its stack data is invalidated and be overwritten by the next stack usage. So, the answer is “yes, if you’re very careful”.

Regards

Paul Bunn, UltraBac Software, 425-644-6000
Microsoft MVP - NT/Windows 2000/XP
http://www.ultrabac.com

-----Original Message-----
From: Chtchetkine, Vladimir [mailto:xxxxx@starbase.com]
Sent: Thursday, May 02, 2002 7:23 AM
To: NT Developers Interest List
Subject: [ntdev] Sharing stack-allocated data between threads

Hi everyone!
It’s a kind of paranoid question, but can I share stack-allocated data between different threads?
I mean can thread stack be viewed as “just another pool” of memory that is available from all other
threads?
Sorry, I guess it’s been too much of work and beer yesterday :slight_smile:


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


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

Actually it is done frequently. For example, a stack allocated event object
may be used as IO completion context. You do have to be very careful that
the owning thread’s stack is not paged out if the users can be running at >=
DISPATCH_LEVEL.

-----Original Message-----
From: int3 [mailto:xxxxx@aalayance.com]
Sent: Thursday, May 02, 2002 12:44 PM
To: NT Developers Interest List
Subject: [ntdev] RE: Sharing stack-allocated data between threads

No, You cannot - I am sure, u will screw me, if u use my thread stack :slight_smile:

----- Original Message -----
From: Chtchetkine, Vladimir
To: NT Developers Interest List
Sent: Thursday, May 02, 2002 9:46 PM
Subject: [ntdev] RE: Sharing stack-allocated data between threads

Nope! I’m refering to KM thread stack.
-----Original Message-----
From: Paul Bunn [mailto:xxxxx@UltraBac.com]
Sent: Thursday, May 02, 2002 8:54 AM
To: NT Developers Interest List
Subject: [ntdev] RE: Sharing stack-allocated data between threads

I’m assuming you’re refering to user-mode.
Since all memory in a process is shared between all threads of that process,
the stacks all share the same process memory so you can “get at” other
threads’ memory. However, there is the obvious problem that if a function
returns all its stack data is invalidated and be overwritten by the next
stack usage. So, the answer is “yes, if you’re very careful”.
Regards
Paul Bunn, UltraBac Software, 425-644-6000
Microsoft MVP - NT/Windows 2000/XP
http://www.ultrabac.com

-----Original Message-----
From: Chtchetkine, Vladimir [mailto:xxxxx@starbase.com]
Sent: Thursday, May 02, 2002 7:23 AM
To: NT Developers Interest List
Subject: [ntdev] Sharing stack-allocated data between threads

Hi everyone!
It’s a kind of paranoid question, but can I share stack-allocated data
between different threads?
I mean can thread stack be viewed as “just another pool” of memory that is
available from all other
threads?
Sorry, I guess it’s been too much of work and beer yesterday :slight_smile:

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

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

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

Oh and you of course have to be equally careful that the owning thread does
not leave the stack frame containing the data while there are outstanding
references to that data. For example, timed waits that can result in
function exits are very dubious coding practices when the event object is
stack based.

-----Original Message-----
From: Roddy, Mark [mailto:xxxxx@stratus.com]
Sent: Thursday, May 02, 2002 1:02 PM
To: NT Developers Interest List
Subject: [ntdev] RE: Sharing stack-allocated data between threads

Actually it is done frequently. For example, a stack
allocated event object may be used as IO completion context.
You do have to be very careful that the owning thread’s stack
is not paged out if the users can be running at >= DISPATCH_LEVEL.

-----Original Message-----
From: int3 [mailto:xxxxx@aalayance.com]
Sent: Thursday, May 02, 2002 12:44 PM
To: NT Developers Interest List
Subject: [ntdev] RE: Sharing stack-allocated data between threads

No, You cannot - I am sure, u will screw me, if u use my
thread stack :slight_smile:

----- Original Message -----
From: Chtchetkine, Vladimir
To: NT Developers Interest List
Sent: Thursday, May 02, 2002 9:46 PM
Subject: [ntdev] RE: Sharing stack-allocated data between threads

Nope! I’m refering to KM thread stack.
-----Original Message-----
From: Paul Bunn [mailto:xxxxx@UltraBac.com]
Sent: Thursday, May 02, 2002 8:54 AM
To: NT Developers Interest List
Subject: [ntdev] RE: Sharing stack-allocated data between threads

I’m assuming you’re refering to user-mode.
Since all memory in a process is shared between all threads
of that process, the stacks all share the same process memory
so you can “get at” other threads’ memory. However, there is
the obvious problem that if a function returns all its stack
data is invalidated and be overwritten by the next stack
usage. So, the answer is “yes, if you’re very careful”. Regards
Paul Bunn, UltraBac Software, 425-644-6000
Microsoft MVP - NT/Windows 2000/XP
http://www.ultrabac.com

-----Original Message-----
From: Chtchetkine, Vladimir
[mailto:xxxxx@starbase.com]
Sent: Thursday,
May 02, 2002 7:23 AM
To: NT Developers Interest List
Subject: [ntdev] Sharing stack-allocated data between threads

Hi everyone!
It’s a kind of paranoid question, but can I share
stack-allocated data between different threads?
I mean can thread stack be viewed as “just another pool” of
memory that is available from all other
threads?
Sorry, I guess it’s been too much of work and beer yesterday :slight_smile:

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

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

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


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

Can u explain bit more please.

----- Original Message -----
From: “Roddy, Mark”
To: “NT Developers Interest List”
Sent: Thursday, May 02, 2002 10:32 PM
Subject: [ntdev] RE: Sharing stack-allocated data between threads

> Actually it is done frequently. For example, a stack allocated event
object
> may be used as IO completion context. You do have to be very careful that
> the owning thread’s stack is not paged out if the users can be running at
>=
> DISPATCH_LEVEL.
>
>
>
> -----Original Message-----
> From: int3 [mailto:xxxxx@aalayance.com]
> Sent: Thursday, May 02, 2002 12:44 PM
> To: NT Developers Interest List
> Subject: [ntdev] RE: Sharing stack-allocated data between threads
>
>
> No, You cannot - I am sure, u will screw me, if u use my thread stack :slight_smile:
>
> ----- Original Message -----
> From: Chtchetkine, Vladimir
> To: NT Developers Interest List
> Sent: Thursday, May 02, 2002 9:46 PM
> Subject: [ntdev] RE: Sharing stack-allocated data between threads
>
>
> Nope! I’m refering to KM thread stack.
> -----Original Message-----
> From: Paul Bunn [mailto:xxxxx@UltraBac.com]
> Sent: Thursday, May 02, 2002 8:54 AM
> To: NT Developers Interest List
> Subject: [ntdev] RE: Sharing stack-allocated data between threads
>
>
> I’m assuming you’re refering to user-mode.
> Since all memory in a process is shared between all threads of that
process,
> the stacks all share the same process memory so you can “get at” other
> threads’ memory. However, there is the obvious problem that if a function
> returns all its stack data is invalidated and be overwritten by the next
> stack usage. So, the answer is “yes, if you’re very careful”.
> Regards
> Paul Bunn, UltraBac Software, 425-644-6000
> Microsoft MVP - NT/Windows 2000/XP
> http://www.ultrabac.com
>
>
> -----Original Message-----
> From: Chtchetkine, Vladimir [mailto:xxxxx@starbase.com]
> Sent: Thursday, May 02, 2002 7:23 AM
> To: NT Developers Interest List
> Subject: [ntdev] Sharing stack-allocated data between threads
>
>
> Hi everyone!
> It’s a kind of paranoid question, but can I share stack-allocated data
> between different threads?
> I mean can thread stack be viewed as “just another pool” of memory that is
> available from all other
> threads?
> Sorry, I guess it’s been too much of work and beer yesterday :slight_smile:
> —
> You are currently subscribed to ntdev as:
xxxxx@Starbase.com
> To unsubscribe send a blank email to %%email.unsub%%
> —
> You are currently subscribed to ntdev as: xxxxx@aalayance.com
> To unsubscribe send a blank email to %%email.unsub%%
> —
> You are currently subscribed to ntdev as: xxxxx@stratus.com
> To unsubscribe send a blank email to %%email.unsub%%
>
> —
> You are currently subscribed to ntdev as: xxxxx@aalayance.com
> To unsubscribe send a blank email to %%email.unsub%%
>

you also need to be careful about the amount of stack space you use
doing this. kernel stacks do not grow and aren’t very big … if you
run off the end of them the system will bugcheck. This may not seem
like a big deal if your driver is on the top of the stack, but for those
of us at the bottom it’s a real pain.

-p

-----Original Message-----
From: Roddy, Mark [mailto:xxxxx@stratus.com]
Sent: Thursday, May 02, 2002 10:02 AM
To: NT Developers Interest List
Subject: [ntdev] RE: Sharing stack-allocated data between threads

Actually it is done frequently. For example, a stack allocated event
object may be used as IO completion context. You do have to be very
careful that the owning thread’s stack is not paged out if the users can
be running at >= DISPATCH_LEVEL.

-----Original Message-----
From: int3 [mailto:xxxxx@aalayance.com]
Sent: Thursday, May 02, 2002 12:44 PM
To: NT Developers Interest List
Subject: [ntdev] RE: Sharing stack-allocated data between threads

No, You cannot - I am sure, u will screw me, if u use my thread stack
:slight_smile:

----- Original Message -----
From: Chtchetkine, Vladimir
To: NT Developers Interest List
Sent: Thursday, May 02, 2002 9:46 PM
Subject: [ntdev] RE: Sharing stack-allocated data between threads

Nope! I’m refering to KM thread stack.
-----Original Message-----
From: Paul Bunn [mailto:xxxxx@UltraBac.com]
Sent: Thursday, May 02, 2002 8:54 AM
To: NT Developers Interest List
Subject: [ntdev] RE: Sharing stack-allocated data between threads

I’m assuming you’re refering to user-mode.
Since all memory in a process is shared between all threads of that
process, the stacks all share the same process memory so you can “get
at” other threads’ memory. However, there is the obvious problem that
if a function returns all its stack data is invalidated and be
overwritten by the next stack usage. So, the answer is “yes, if you’re
very careful”. Regards
Paul Bunn, UltraBac Software, 425-644-6000
Microsoft MVP - NT/Windows 2000/XP
http://www.ultrabac.com

-----Original Message-----
From: Chtchetkine, Vladimir [mailto:xxxxx@starbase.com]
Sent: Thursday, May 02, 2002 7:23 AM
To: NT Developers Interest List
Subject: [ntdev] Sharing stack-allocated data between threads

Hi everyone!
It’s a kind of paranoid question, but can I share stack-allocated data
between different threads?
I mean can thread stack be viewed as “just another pool” of memory that
is available from all other
threads?
Sorry, I guess it’s been too much of work and beer yesterday :slight_smile:

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

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

You are currently subscribed to ntdev as: xxxxx@stratus.com 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%%

Thank you, Mark!

Actually I was concerned that thread stack (being a “very special tiny
creature”) may have special treatment in the OS,
like not being available in the context of another thread. Don’t ask me why,
it was just a nightmare :slight_smile:

-----Original Message-----
From: Roddy, Mark [mailto:xxxxx@stratus.com]
Sent: Thursday, May 02, 2002 10:13 AM
To: NT Developers Interest List
Subject: [ntdev] RE: Sharing stack-allocated data between threads

Oh and you of course have to be equally careful that the owning thread does
not leave the stack frame containing the data while there are outstanding
references to that data. For example, timed waits that can result in
function exits are very dubious coding practices when the event object is
stack based.

-----Original Message-----
From: Roddy, Mark [mailto:xxxxx@stratus.com]
Sent: Thursday, May 02, 2002 1:02 PM
To: NT Developers Interest List
Subject: [ntdev] RE: Sharing stack-allocated data between threads

Actually it is done frequently. For example, a stack
allocated event object may be used as IO completion context.
You do have to be very careful that the owning thread’s stack
is not paged out if the users can be running at >= DISPATCH_LEVEL.

-----Original Message-----
From: int3 [mailto:xxxxx@aalayance.com]
Sent: Thursday, May 02, 2002 12:44 PM
To: NT Developers Interest List
Subject: [ntdev] RE: Sharing stack-allocated data between threads

No, You cannot - I am sure, u will screw me, if u use my
thread stack :slight_smile:

----- Original Message -----
From: Chtchetkine, Vladimir
To: NT Developers Interest List
Sent: Thursday, May 02, 2002 9:46 PM
Subject: [ntdev] RE: Sharing stack-allocated data between threads

Nope! I’m refering to KM thread stack.
-----Original Message-----
From: Paul Bunn [mailto:xxxxx@UltraBac.com]
Sent: Thursday, May 02, 2002 8:54 AM
To: NT Developers Interest List
Subject: [ntdev] RE: Sharing stack-allocated data between threads

I’m assuming you’re refering to user-mode.
Since all memory in a process is shared between all threads
of that process, the stacks all share the same process memory
so you can “get at” other threads’ memory. However, there is
the obvious problem that if a function returns all its stack
data is invalidated and be overwritten by the next stack
usage. So, the answer is “yes, if you’re very careful”. Regards
Paul Bunn, UltraBac Software, 425-644-6000
Microsoft MVP - NT/Windows 2000/XP
http://www.ultrabac.com

-----Original Message-----
From: Chtchetkine, Vladimir
[mailto:xxxxx@starbase.com]
Sent: Thursday,
May 02, 2002 7:23 AM
To: NT Developers Interest List
Subject: [ntdev] Sharing stack-allocated data between threads

Hi everyone!
It’s a kind of paranoid question, but can I share
stack-allocated data between different threads?
I mean can thread stack be viewed as “just another pool” of
memory that is available from all other
threads?
Sorry, I guess it’s been too much of work and beer yesterday :slight_smile:

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

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

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


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


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

Yes, I’m well aware of this. But here I have another paranoia about using
the pool or, actually, “abusing” the pool.
A couple of years ago I’ve spent a considerable amount of time trying to
figure out what’s going on with the system
performance after my driver has been working for a while (as time flew
performance degraded significantly) and it
turned out that this was “just” because of pool fragmentation. So after that
I think twice before making decision
from where allocate memory that I need.

-----Original Message-----
From: Peter Wieland [mailto:xxxxx@windows.microsoft.com]
Sent: Thursday, May 02, 2002 10:16 AM
To: NT Developers Interest List
Subject: [ntdev] RE: Sharing stack-allocated data between threads

you also need to be careful about the amount of stack space you use
doing this. kernel stacks do not grow and aren’t very big … if you
run off the end of them the system will bugcheck. This may not seem
like a big deal if your driver is on the top of the stack, but for those
of us at the bottom it’s a real pain.

-p

-----Original Message-----
From: Roddy, Mark [mailto:xxxxx@stratus.com]
Sent: Thursday, May 02, 2002 10:02 AM
To: NT Developers Interest List
Subject: [ntdev] RE: Sharing stack-allocated data between threads

Actually it is done frequently. For example, a stack allocated event
object may be used as IO completion context. You do have to be very
careful that the owning thread’s stack is not paged out if the users can
be running at >= DISPATCH_LEVEL.

-----Original Message-----
From: int3 [mailto:xxxxx@aalayance.com]
Sent: Thursday, May 02, 2002 12:44 PM
To: NT Developers Interest List
Subject: [ntdev] RE: Sharing stack-allocated data between threads

No, You cannot - I am sure, u will screw me, if u use my thread stack
:slight_smile:

----- Original Message -----
From: Chtchetkine, Vladimir
To: NT Developers Interest List
Sent: Thursday, May 02, 2002 9:46 PM
Subject: [ntdev] RE: Sharing stack-allocated data between threads

Nope! I’m refering to KM thread stack.
-----Original Message-----
From: Paul Bunn [mailto:xxxxx@UltraBac.com]
Sent: Thursday, May 02, 2002 8:54 AM
To: NT Developers Interest List
Subject: [ntdev] RE: Sharing stack-allocated data between threads

I’m assuming you’re refering to user-mode.
Since all memory in a process is shared between all threads of that
process, the stacks all share the same process memory so you can “get
at” other threads’ memory. However, there is the obvious problem that
if a function returns all its stack data is invalidated and be
overwritten by the next stack usage. So, the answer is “yes, if you’re
very careful”. Regards
Paul Bunn, UltraBac Software, 425-644-6000
Microsoft MVP - NT/Windows 2000/XP
http://www.ultrabac.com

-----Original Message-----
From: Chtchetkine, Vladimir [mailto:xxxxx@starbase.com]
Sent: Thursday, May 02, 2002 7:23 AM
To: NT Developers Interest List
Subject: [ntdev] Sharing stack-allocated data between threads

Hi everyone!
It’s a kind of paranoid question, but can I share stack-allocated data
between different threads?
I mean can thread stack be viewed as “just another pool” of memory that
is available from all other
threads?
Sorry, I guess it’s been too much of work and beer yesterday :slight_smile:

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

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

You are currently subscribed to ntdev as: xxxxx@stratus.com 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%%


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

RE: [ntdev] RE: Sharing stack-allocated data between threadsHave you
considered allocating everything you need at Init time, so you don’t have to
sweat any of this?

Phil

“Chtchetkine, Vladimir” wrote in message
news:xxxxx@ntdev…
Yes, I’m well aware of this. But here I have another paranoia about using
the pool or, actually, “abusing” the pool.
A couple of years ago I’ve spent a considerable amount of time trying to
figure out what’s going on with the system
performance after my driver has been working for a while (as time flew
performance degraded significantly) and it
turned out that this was “just” because of pool fragmentation. So after that
I think twice before making decision
from where allocate memory that I need.

I didn’t get where is “ha-ha” here, sorry :frowning:

-----Original Message-----
From: Phil Barila [mailto:xxxxx@Seagate.com]
Sent: Thursday, May 02, 2002 11:27 AM
To: NT Developers Interest List
Subject: [ntdev] Re: Sharing stack-allocated data between threads

RE: [ntdev] RE: Sharing stack-allocated data between threadsHave you
considered allocating everything you need at Init time, so you don’t have to
sweat any of this?

Phil

“Chtchetkine, Vladimir” wrote in message
news:xxxxx@ntdev…
Yes, I’m well aware of this. But here I have another paranoia about using
the pool or, actually, “abusing” the pool.
A couple of years ago I’ve spent a considerable amount of time trying to
figure out what’s going on with the system
performance after my driver has been working for a while (as time flew
performance degraded significantly) and it
turned out that this was “just” because of pool fragmentation. So after that
I think twice before making decision
from where allocate memory that I need.


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

RE: [ntdev] Re: Sharing stack-allocated data between threads
It wasn’t intended to be a joke, though there might be some humor in it
anyway… If I understood your problem statement, a few years ago you found
that you were seeing a performance degradation over time caused by pool
fragmentation. That suggests that your architecture used run-time
allocation and de-allocation. So your solution was to limit the use of the
pool as much as possible, and now that answer has led you to your current
situation where you are doing stack gymnastics across threads, an
architecture which is just asking for BSOD’s. It’s possible, but very tough
to get right all the time. So are you sure you wouldn’t rather grab a big
chunk of memory at initialization and manage it yourself? How is this any
worse than trying to share stack space across threads?

Phil

“Chtchetkine, Vladimir” wrote in message
news:xxxxx@ntdev…
I didn’t get where is “ha-ha” here, sorry :frowning:

-----Original Message-----
From: Phil Barila [mailto:xxxxx@Seagate.com]
Sent: Thursday, May 02, 2002 11:27 AM
To: NT Developers Interest List
Subject: [ntdev] Re: Sharing stack-allocated data between threads

RE: [ntdev] RE: Sharing stack-allocated data between threadsHave you
considered allocating everything you need at Init time, so you don’t have to
sweat any of this?
Phil
“Chtchetkine, Vladimir” wrote in message
news:xxxxx@ntdev…
Yes, I’m well aware of this. But here I have another paranoia about using
the pool or, actually, “abusing” the pool.
A couple of years ago I’ve spent a considerable amount of time trying to
figure out what’s going on with the system
performance after my driver has been working for a while (as time flew
performance degraded significantly) and it
turned out that this was “just” because of pool fragmentation. So after that
I think twice before making decision
from where allocate memory that I need.


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

Sharing stack-allocated data between threadsThat would not be recommandable
in kernel mode, thread stack can be swapped into page file…in kernel
mode, at an IRQL higher than APC_LEVEL, a reference to this area causes a
BSOD. Use nonpaged pool instead.

Johnny

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Chtchetkine, Vladimir
Sent: Donnerstag, 2. Mai 2002 16:23
To: NT Developers Interest List
Subject: [ntdev] Sharing stack-allocated data between threads

Hi everyone!

It’s a kind of paranoid question, but can I share stack-allocated data
between different threads?
I mean can thread stack be viewed as “just another pool” of memory that is
available from all other
threads?

Sorry, I guess it’s been too much of work and beer yesterday :slight_smile:

TIA,

Vladimir


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

Kernel stack is 8KB. not so big but as long as there are not so many nested
functions, it is pretty improbable that you run out of
stack…IRQL>APC_LEVEL and the fact that kernel stack can be swapped out are
more dangerous; you can lock the physical pages or make the thread to wait
on a dispatcher object and use KernelMode as WaitMode in
KeWaitForSingleObject, in this case the thread stack is not swapped
out…but lots of other problems… NPP is the right way.

Johnny

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Peter Wieland
Sent: Donnerstag, 2. Mai 2002 19:16
To: NT Developers Interest List
Subject: [ntdev] RE: Sharing stack-allocated data between threads

you also need to be careful about the amount of stack space you use
doing this. kernel stacks do not grow and aren’t very big … if you
run off the end of them the system will bugcheck. This may not seem
like a big deal if your driver is on the top of the stack, but for those
of us at the bottom it’s a real pain.

-p

-----Original Message-----
From: Roddy, Mark [mailto:xxxxx@stratus.com]
Sent: Thursday, May 02, 2002 10:02 AM
To: NT Developers Interest List
Subject: [ntdev] RE: Sharing stack-allocated data between threads

Actually it is done frequently. For example, a stack allocated event
object may be used as IO completion context. You do have to be very
careful that the owning thread’s stack is not paged out if the users can
be running at >= DISPATCH_LEVEL.

-----Original Message-----
From: int3 [mailto:xxxxx@aalayance.com]
Sent: Thursday, May 02, 2002 12:44 PM
To: NT Developers Interest List
Subject: [ntdev] RE: Sharing stack-allocated data between threads

No, You cannot - I am sure, u will screw me, if u use my thread stack
:slight_smile:

----- Original Message -----
From: Chtchetkine, Vladimir
To: NT Developers Interest List
Sent: Thursday, May 02, 2002 9:46 PM
Subject: [ntdev] RE: Sharing stack-allocated data between threads

Nope! I’m refering to KM thread stack.
-----Original Message-----
From: Paul Bunn [mailto:xxxxx@UltraBac.com]
Sent: Thursday, May 02, 2002 8:54 AM
To: NT Developers Interest List
Subject: [ntdev] RE: Sharing stack-allocated data between threads

I’m assuming you’re refering to user-mode.
Since all memory in a process is shared between all threads of that
process, the stacks all share the same process memory so you can “get
at” other threads’ memory. However, there is the obvious problem that
if a function returns all its stack data is invalidated and be
overwritten by the next stack usage. So, the answer is “yes, if you’re
very careful”. Regards
Paul Bunn, UltraBac Software, 425-644-6000
Microsoft MVP - NT/Windows 2000/XP
http://www.ultrabac.com

-----Original Message-----
From: Chtchetkine, Vladimir [mailto:xxxxx@starbase.com]
Sent: Thursday, May 02, 2002 7:23 AM
To: NT Developers Interest List
Subject: [ntdev] Sharing stack-allocated data between threads

Hi everyone!
It’s a kind of paranoid question, but can I share stack-allocated data
between different threads?
I mean can thread stack be viewed as “just another pool” of memory that
is available from all other
threads?
Sorry, I guess it’s been too much of work and beer yesterday :slight_smile:

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

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

You are currently subscribed to ntdev as: xxxxx@stratus.com 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%%


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


Do You Yahoo!?

Get your free @yahoo.com address at http://mail.yahoo.com

It’s a simple thing to allocate your own stack and switch to it, if stack
size is a problem. But why not have a shared “guardian” thread, put the
stuff you want to share in TLS, and pass the address to the other threads ?
Stacks weren’t meant to be shared by coroutines !

Alberto.

-----Original Message-----
From: Johnny [mailto:xxxxx@yahoo.de]
Sent: Thursday, May 02, 2002 3:57 PM
To: NT Developers Interest List
Subject: [ntdev] RE: Sharing stack-allocated data between threads

Kernel stack is 8KB. not so big but as long as there are not so many nested
functions, it is pretty improbable that you run out of
stack…IRQL>APC_LEVEL and the fact that kernel stack can be swapped out are
more dangerous; you can lock the physical pages or make the thread to wait
on a dispatcher object and use KernelMode as WaitMode in
KeWaitForSingleObject, in this case the thread stack is not swapped
out…but lots of other problems… NPP is the right way.

Johnny

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Peter Wieland
Sent: Donnerstag, 2. Mai 2002 19:16
To: NT Developers Interest List
Subject: [ntdev] RE: Sharing stack-allocated data between threads

you also need to be careful about the amount of stack space you use
doing this. kernel stacks do not grow and aren’t very big … if you
run off the end of them the system will bugcheck. This may not seem
like a big deal if your driver is on the top of the stack, but for those
of us at the bottom it’s a real pain.

-p

-----Original Message-----
From: Roddy, Mark [mailto:xxxxx@stratus.com]
Sent: Thursday, May 02, 2002 10:02 AM
To: NT Developers Interest List
Subject: [ntdev] RE: Sharing stack-allocated data between threads

Actually it is done frequently. For example, a stack allocated event
object may be used as IO completion context. You do have to be very
careful that the owning thread’s stack is not paged out if the users can
be running at >= DISPATCH_LEVEL.

-----Original Message-----
From: int3 [mailto:xxxxx@aalayance.com]
Sent: Thursday, May 02, 2002 12:44 PM
To: NT Developers Interest List
Subject: [ntdev] RE: Sharing stack-allocated data between threads

No, You cannot - I am sure, u will screw me, if u use my thread stack
:slight_smile:

----- Original Message -----
From: Chtchetkine, Vladimir
To: NT Developers Interest List
Sent: Thursday, May 02, 2002 9:46 PM
Subject: [ntdev] RE: Sharing stack-allocated data between threads

Nope! I’m refering to KM thread stack.
-----Original Message-----
From: Paul Bunn [mailto:xxxxx@UltraBac.com]
Sent: Thursday, May 02, 2002 8:54 AM
To: NT Developers Interest List
Subject: [ntdev] RE: Sharing stack-allocated data between threads

I’m assuming you’re refering to user-mode.
Since all memory in a process is shared between all threads of that
process, the stacks all share the same process memory so you can “get
at” other threads’ memory. However, there is the obvious problem that
if a function returns all its stack data is invalidated and be
overwritten by the next stack usage. So, the answer is “yes, if you’re
very careful”. Regards
Paul Bunn, UltraBac Software, 425-644-6000
Microsoft MVP - NT/Windows 2000/XP
http://www.ultrabac.com

-----Original Message-----
From: Chtchetkine, Vladimir [mailto:xxxxx@starbase.com]
Sent: Thursday, May 02, 2002 7:23 AM
To: NT Developers Interest List
Subject: [ntdev] Sharing stack-allocated data between threads

Hi everyone!
It’s a kind of paranoid question, but can I share stack-allocated data
between different threads?
I mean can thread stack be viewed as “just another pool” of memory that
is available from all other
threads?
Sorry, I guess it’s been too much of work and beer yesterday :slight_smile:

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

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

You are currently subscribed to ntdev as: xxxxx@stratus.com 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%%


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


Do You Yahoo!?

Get your free @yahoo.com address at http://mail.yahoo.com


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

The contents of this e-mail are intended for the named addressee only. It
contains information that may be confidential. Unless you are the named
addressee or an authorized designee, you may not copy or use it, or disclose
it to anyone else. If you received it in error please notify us immediately
and then destroy it.

I mean that the following is commonplace.

THREAD1:

foo()
{
KEVENT event; // on the stack, yes?

.
.
KeInitializeEvent(&event,…);

IoSetCompletionRoutine(Irp, fooComplete, &event, …);

IoCallDriver(LowerDevObj, Irp);

KeWaitForSingleObject(&event, …);

.
.
}

SOME OTHER THREAD:
fooComplete(IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN PVOID Context // this is a pointer to some thread’s stack!
)
{

.
.
.
KeSetEvent((PRKEVENT)Context, …);
.
.
return STATUS_MORE_PROCESSING_REQUIRED;
}

-----Original Message-----
From: int3 [mailto:xxxxx@aalayance.com]
Sent: Thursday, May 02, 2002 1:22 PM
To: NT Developers Interest List
Subject: [ntdev] RE: Sharing stack-allocated data between threads

Can u explain bit more please.

----- Original Message -----
From: “Roddy, Mark”
> To: “NT Developers Interest List”
> Sent: Thursday, May 02, 2002 10:32 PM
> Subject: [ntdev] RE: Sharing stack-allocated data between threads
>
>
> > Actually it is done frequently. For example, a stack allocated event
> object
> > may be used as IO completion context. You do have to be
> very careful
> >that the owning thread’s stack is not paged out if the users can be
> >running at = DISPATCH_LEVEL.
> >
> >
> >
> > -----Original Message-----
> > From: int3 [mailto:xxxxx@aalayance.com]
> > Sent: Thursday, May 02, 2002 12:44 PM
> > To: NT Developers Interest List
> > Subject: [ntdev] RE: Sharing stack-allocated data between threads
> >
> >
> > No, You cannot - I am sure, u will screw me, if u use my
> thread stack
> > :slight_smile:
> >
> > ----- Original Message -----
> > From: Chtchetkine, Vladimir
> > To: NT Developers Interest List
> > Sent: Thursday, May 02, 2002 9:46 PM
> > Subject: [ntdev] RE: Sharing stack-allocated data between threads
> >
> >
> > Nope! I’m refering to KM thread stack.
> > -----Original Message-----
> > From: Paul Bunn [mailto:xxxxx@UltraBac.com]
> > Sent: Thursday, May 02, 2002 8:54 AM
> > To: NT Developers Interest List
> > Subject: [ntdev] RE: Sharing stack-allocated data between threads
> >
> >
> > I’m assuming you’re refering to user-mode.
> > Since all memory in a process is shared between all threads of that
> process,
> > the stacks all share the same process memory so you can
> “get at” other
> > threads’ memory. However, there is the obvious problem that if a
> > function returns all its stack data is invalidated and be
> overwritten
> > by the next stack usage. So, the answer is “yes, if you’re very
> > careful”. Regards Paul Bunn, UltraBac Software, 425-644-6000
> > Microsoft MVP - NT/Windows 2000/XP
> > http://www.ultrabac.com
> >
> >
> > -----Original Message-----
> > From: Chtchetkine, Vladimir
> [mailto:xxxxx@starbase.com]
> > Sent: Thursday,
> May 02, 2002 7:23 AM
> > To: NT Developers Interest List
> > Subject: [ntdev] Sharing stack-allocated data between threads
> >
> >
> > Hi everyone!
> > It’s a kind of paranoid question, but can I share
> stack-allocated data
> > between different threads? I mean can thread stack be
> viewed as “just
> > another pool” of memory that is available from all other
> > threads?
> > Sorry, I guess it’s been too much of work and beer yesterday :slight_smile:
> > —
> > You are currently subscribed to ntdev as:
> xxxxx@Starbase.com
> > To unsubscribe send a blank email to %%email.unsub%%
> > —
> > You are currently subscribed to ntdev as: xxxxx@aalayance.com To
> > unsubscribe send a blank email to %%email.unsub%%
> > —
> > You are currently subscribed to ntdev as: xxxxx@stratus.com To
> > unsubscribe send a blank email to %%email.unsub%%
> >
> > —
> > You are currently subscribed to ntdev as: xxxxx@aalayance.com To
> > unsubscribe send a blank email to %%email.unsub%%
> >
>
>
> —
> You are currently subscribed to ntdev as:
> xxxxx@stratus.com To unsubscribe send a blank email to
> %%email.unsub%%
>

Well, to some extent writing device drivers itself is asking for BSOD’s.
After all, If there
were no drivers there wouldn’t be BSOD’s :slight_smile:
To finish this up: I needed a place where to allocate an object that has an
event /event itself
is allocated from NP, I know :-)/ on which event I’ll block current thread
until another thread
signals the event. But before (and only before) signaling the event the
second thread had to
perform some operations on the allocated object. So, the object is small and
stays on the frequent
path which is a pattern developped for performace hit condition. That’s why
I thought about allocating
it on the stack. But then I’ve got this doubt about stack availability
accross threads and things
got started. When the question got clarified I don’t see anything wrong in
this architecture.
After second thought I found your initial proposal similar to my solution
(without necessity to
reinvent anything, though). I simply use lookaside lists for frequent block
allocs/dealocs. To some
extent it’s what you have proposed :slight_smile:

-----Original Message-----
From: Phil Barila [mailto:xxxxx@Seagate.com]
Sent: Thursday, May 02, 2002 12:06 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Sharing stack-allocated data between threads

RE: [ntdev] Re: Sharing stack-allocated data between threads
It wasn’t intended to be a joke, though there might be some humor in it
anyway… If I understood your problem statement, a few years ago you found
that you were seeing a performance degradation over time caused by pool
fragmentation. That suggests that your architecture used run-time
allocation and de-allocation. So your solution was to limit the use of the
pool as much as possible, and now that answer has led you to your current
situation where you are doing stack gymnastics across threads, an
architecture which is just asking for BSOD’s. It’s possible, but very tough
to get right all the time. So are you sure you wouldn’t rather grab a big
chunk of memory at initialization and manage it yourself? How is this any
worse than trying to share stack space across threads?

Phil

“Chtchetkine, Vladimir” wrote in message
news:xxxxx@ntdev…
I didn’t get where is “ha-ha” here, sorry :frowning:

-----Original Message-----
From: Phil Barila [mailto:xxxxx@Seagate.com]
Sent: Thursday, May 02, 2002 11:27 AM
To: NT Developers Interest List
Subject: [ntdev] Re: Sharing stack-allocated data between threads

RE: [ntdev] RE: Sharing stack-allocated data between threadsHave you
considered allocating everything you need at Init time, so you don’t have to
sweat any of this?
Phil
“Chtchetkine, Vladimir” wrote in message
news:xxxxx@ntdev…
Yes, I’m well aware of this. But here I have another paranoia about using
the pool or, actually, “abusing” the pool.
A couple of years ago I’ve spent a considerable amount of time trying to
figure out what’s going on with the system
performance after my driver has been working for a while (as time flew
performance degraded significantly) and it
turned out that this was “just” because of pool fragmentation. So after that
I think twice before making decision
from where allocate memory that I need.


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


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

> Actually it is done frequently. For example, a stack allocated event object

may be used as IO completion context.

…and work queue item too, if you wait on its completion just below.
A common pattern when you need a System process context.

Max

Sharing stack-allocated data between threadsWrong.
Signaling the on-stack event from the completion routine is fine.
Kernel stack can be swapped only if the thread is in the user mode wait.

Max
----- Original Message -----
From: Johnny
To: NT Developers Interest List
Sent: Thursday, May 02, 2002 11:36 PM
Subject: [ntdev] RE: Sharing stack-allocated data between threads

That would not be recommandable in kernel mode, thread stack can be swapped into page file…in kernel mode, at an IRQL higher than APC_LEVEL, a reference to this area causes a BSOD. Use nonpaged pool instead.

Johnny

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com]On Behalf Of Chtchetkine, Vladimir
Sent: Donnerstag, 2. Mai 2002 16:23
To: NT Developers Interest List
Subject: [ntdev] Sharing stack-allocated data between threads

Hi everyone!

It’s a kind of paranoid question, but can I share stack-allocated data between different threads?
I mean can thread stack be viewed as “just another pool” of memory that is available from all other
threads?

Sorry, I guess it’s been too much of work and beer yesterday :slight_smile:

TIA,

Vladimir


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

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