GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Set pipeline thread stack size · PowerShell/PowerShell@1f10add

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src/System.Management.Automation/engine/hostifaces
    • LocalPipeline.cs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/System.Management.Automation/engine/hostifaces/LocalPipeline.cs‎

Copy file name to clipboardExpand all lines: src/System.Management.Automation/engine/hostifaces/LocalPipeline.cs
+15-55Lines changed: 15 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ namespace System.Management.Automation.Runspaces
2020
/// </summary>
2121
internal sealed class LocalPipeline : PipelineBase
2222
{
23+
// Default stack size in bytes for local pipeline threads.
24+
//
25+
// Each platform uses different default for the thread stack size:
26+
// - Windows 2 MB
27+
// - Linux 8 Mb
28+
// - MacOs 512 KB
29+
// We should use the same default for all platforms to get predictable behavior.
30+
internal const int DefaultPipelineStackSize = 10_000_000;
31+
2332
#region constructors
2433

2534
/// <summary>
@@ -152,12 +161,12 @@ protected override void StartPipelineExecution()
152161
#if CORECLR
153162
//Start execution of pipeline in another thread
154163
// No ApartmentState/ThreadStackSize In CoreCLR
155-
Thread invokeThread = new Thread(new ThreadStart(this.InvokeThreadProc));
164+
Thread invokeThread = new Thread(new ThreadStart(this.InvokeThreadProc), DefaultPipelineStackSize);
156165
SetupInvokeThread(invokeThread, true);
157166
#else
158167
//Start execution of pipeline in another thread
159168
// 2004/05/02-JonN Specify maxStack parameter
160-
Thread invokeThread = new Thread(new ThreadStart(this.InvokeThreadProc), MaxStack);
169+
Thread invokeThread = new Thread(new ThreadStart(this.InvokeThreadProc), DefaultPipelineStackSize);
161170
SetupInvokeThread(invokeThread, true);
162171

163172
ApartmentState apartmentState;
@@ -245,55 +254,6 @@ private void SetupInvokeThread(Thread invokeThread, bool changeName)
245254
}
246255
}
247256

248-
#if !CORECLR
249-
/// <summary>
250-
/// Stack Reserve setting for pipeline threads
251-
/// </summary>
252-
internal static int MaxStack
253-
{
254-
get
255-
{
256-
int i = ReadRegistryInt("PipelineMaxStackSizeMB", 10);
257-
if (i < 10)
258-
i = 10; // minimum 10MB
259-
else if (i > 100)
260-
i = 100; // maximum 100MB
261-
return i * 1000000;
262-
}
263-
}
264-
265-
internal static int ReadRegistryInt(string policyValueName, int defaultValue)
266-
{
267-
RegistryKey key;
268-
try
269-
{
270-
key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\PowerShell\\1\\ShellIds");
271-
}
272-
catch (System.Security.SecurityException)
273-
{
274-
return defaultValue;
275-
}
276-
if (null == key)
277-
return defaultValue;
278-
279-
object temp;
280-
try
281-
{
282-
temp = key.GetValue(policyValueName);
283-
}
284-
catch (System.Security.SecurityException)
285-
{
286-
return defaultValue;
287-
}
288-
if (!(temp is int))
289-
{
290-
return defaultValue;
291-
}
292-
int i = (int)temp;
293-
return i;
294-
}
295-
#endif
296-
297257
///<summary>
298258
/// Helper method for asynchronous invoke
299259
///<returns>Unhandled FlowControl exception if InvocationSettings.ExposeFlowControlExceptions is true.</returns>
@@ -1219,25 +1179,25 @@ protected override
12191179
}
12201180

12211181
/// <summary>
1222-
/// Helper class that holds the thread used to execute pipelines when CreateThreadOptions.ReuseThread is used
1182+
/// Helper class that holds the thread used to execute pipelines when CreateThreadOptions.ReuseThread is used.
12231183
/// </summary>
12241184
internal class PipelineThread : IDisposable
12251185
{
12261186
/// <summary>
1227-
/// Creates the worker thread and waits for it to be ready
1187+
/// Creates the worker thread and waits for it to be ready.
12281188
/// </summary>
12291189
#if CORECLR
12301190
internal PipelineThread()
12311191
{
1232-
_worker = new Thread(WorkerProc);
1192+
_worker = new Thread(WorkerProc, LocalPipeline.DefaultPipelineStackSize);
12331193
_workItem = null;
12341194
_workItemReady = new AutoResetEvent(false);
12351195
_closed = false;
12361196
}
12371197
#else
12381198
internal PipelineThread(ApartmentState apartmentState)
12391199
{
1240-
_worker = new Thread(WorkerProc, LocalPipeline.MaxStack);
1200+
_worker = new Thread(WorkerProc, DefaultPipelineStackSize);
12411201
_workItem = null;
12421202
_workItemReady = new AutoResetEvent(false);
12431203
_closed = false;

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.