Skip to content

For an exposure.#7

Open
ewdlop wants to merge 2 commits into
ChadBurggraf:masterfrom
OurDotNetOrganization:master
Open

For an exposure.#7
ewdlop wants to merge 2 commits into
ChadBurggraf:masterfrom
OurDotNetOrganization:master

Conversation

@ewdlop

@ewdlop ewdlop commented Dec 28, 2025

Copy link
Copy Markdown

.NetFramework 4.0 lacks support.

Copoilot: "Update project structure and enhance async capabilities

Updated solution and project files to SDK-style format targeting .NET 9.0. Added new project `ParallelExtensionsExtrasCore` and introduced numerous files with classes and extension methods to improve asynchronous programming, including support for parallel LINQ, asynchronous I/O operations, and enhanced task scheduling features. Modernized the codebase for better usability and performance in multi-threaded environments."
Copilot AI review requested due to automatic review settings December 28, 2025 15:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a comprehensive set of parallel extension utilities to the codebase under the title "For an exposure." The changes introduce multiple task schedulers, parallel algorithms, partitioners, and extension methods for asynchronous programming.

Key Changes:

  • Added 11 custom task schedulers for various execution patterns (work-stealing, round-robin, prioritization, etc.)
  • Implemented parallel algorithm utilities including map-reduce, sorting, scanning, and filtering
  • Added partitioners for chunked and single-item processing
  • Created extensive extension methods for Task, TaskFactory, and LINQ integration

Reviewed changes

Copilot reviewed 83 out of 84 changed files in this pull request and generated 64 comments.

Show a summary per file
File Description
SortedTopN.cs Utility class for maintaining top-N sorted elements
WorkStealingTaskScheduler.cs Task scheduler implementing work-stealing pattern
ThreadPerTaskkScheduler.cs File naming issue: Extra 'k' in filename
Other schedulers (11 files) Various specialized task schedulers for different patterns
Partitioners (2 files) Chunk and single-item partitioning implementations
ParallelAlgorithms (10 files) Map, reduce, sort, scan, and other parallel algorithms
Extensions (20+ files) Extension methods for Task, LINQ, and EAP patterns
ParallelExtensionsExtrasCore.csproj Project configuration targeting .NET 9.0

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// to the resulting task when we're done.
var tasks = new List<Task>();

// Run seqeuentially through all of the provided functions.

Copilot AI Dec 28, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in comment: 'seqeuentially' should be 'sequentially'.

Copilot uses AI. Check for mistakes.
/// <summary>An invalid I/O completion port handle value.</summary>
private IntPtr INVALID_IOCP_HANDLE = IntPtr.Zero;

/// <summary>The I/O completion porth handle.</summary>

Copilot AI Dec 28, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in comment: 'porth' should be 'port'.

Copilot uses AI. Check for mistakes.
(accum) => accum.Values);
}

/// <summary>A comparer that comparers using the inverse of the default comparer.</summary>

Copilot AI Dec 28, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in comment: 'comparers' should be 'compares'.

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +37
//--------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// File: ThreadPerTaskScheduler.cs
//
//--------------------------------------------------------------------------

using System.Collections.Generic;
using System.Linq;

namespace System.Threading.Tasks.Schedulers
{
/// <summary>Provides a task scheduler that dedicates a thread per task.</summary>
public class ThreadPerTaskScheduler : TaskScheduler
{
/// <summary>Gets the tasks currently scheduled to this scheduler.</summary>
/// <remarks>This will always return an empty enumerable, as tasks are launched as soon as they're queued.</remarks>
protected override IEnumerable<Task> GetScheduledTasks() { return Enumerable.Empty<Task>(); }

/// <summary>Starts a new thread to process the provided task.</summary>
/// <param name="task">The task to be executed.</param>
protected override void QueueTask(Task task)
{
new Thread(() => TryExecuteTask(task)) { IsBackground = true }.Start();
}

/// <summary>Runs the provided task on the current thread.</summary>
/// <param name="task">The task to be executed.</param>
/// <param name="taskWasPreviouslyQueued">Ignored.</param>
/// <returns>Whether the task could be executed on the current thread.</returns>
protected override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
{
return TryExecuteTask(task);
}
}
}

Copilot AI Dec 28, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filename contains a typo: 'ThreadPerTaskkScheduler.cs' should be 'ThreadPerTaskScheduler.cs' (extra 'k'). The file header comment on line 5 shows the correct name 'ThreadPerTaskScheduler.cs', indicating this is a file naming issue.

Copilot uses AI. Check for mistakes.
public static partial class TaskFactoryExtensions
{
/// <summary>
/// Creates a continuation Task that will compplete upon

Copilot AI Dec 28, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in comment: 'compplete' should be 'complete'.

Copilot uses AI. Check for mistakes.
/// <summary>Whether this queue has been disposed.</summary>
internal bool _disposed;
/// <summary>Gets the priority for this queue.</summary>
internal int _priority;

Copilot AI Dec 28, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Field '_priority' can be 'readonly'.

Copilot uses AI. Check for mistakes.
/// </summary>
private readonly int _concurrencyLevel;
/// <summary>Whether we're processing tasks on the current thread.</summary>
private static ThreadLocal<bool> _taskProcessingThread = new ThreadLocal<bool>();

Copilot AI Dec 28, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Field '_taskProcessingThread' can be 'readonly'.

Copilot uses AI. Check for mistakes.
private readonly int m_concurrencyLevel;
private readonly Queue<Task> m_queue = new Queue<Task>();
private WorkStealingQueue<Task>[] m_wsQueues = new WorkStealingQueue<Task>[Environment.ProcessorCount];
private Lazy<Thread[]> m_threads;

Copilot AI Dec 28, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Field 'm_threads' can be 'readonly'.

Copilot uses AI. Check for mistakes.
private volatile int m_headIndex = 0;
private volatile int m_tailIndex = 0;

private object m_foreignLock = new object();

Copilot AI Dec 28, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Field 'm_foreignLock' can be 'readonly'.

Copilot uses AI. Check for mistakes.
Comment on lines +426 to +436
if (_targetScheduler == null)
{
// Get all of the tasks, filtering out nulls, which are just placeholders
// for tasks in other sub-schedulers
return _blockingTaskQueue.Where(t => t != null).ToList();
}
// otherwise get them from the non-blocking queue...
else
{
return _nonthreadsafeTaskQueue.Where(t => t != null).ToList();
}

Copilot AI Dec 28, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both branches of this 'if' statement return - consider using '?' to express intent better.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants