Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 177517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:04:06+00:00 2026-05-11T14:04:06+00:00

Assume a multi-threaded environment and a (properly synchronized) class that has one particular procedure

  • 0

Assume a multi-threaded environment and a (properly synchronized) class that has one particular procedure

procedure SortKeyList (KeyList : TList <Integer>; Inverted : Boolean); 

that takes a list of keys and sorts it. The procedure uses the RTL quicksort implementation TList.Sort:

KeyList.Sort (TComparer <Integer>.Construct (CompareKeys)) 

Now for the problem: CompareKeys has to access some members of the class in order to sort the list (that’s the whole point about this class). But the RTL requires CompareKeys to be a normal function. How can I pass data from the object to the CompareKeys function in a thread-safe manner? Obviously using global exchange variables isn’t an option since it is in no way thread-safe.

Any ideas on that?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T14:04:07+00:00Added an answer on May 11, 2026 at 2:04 pm

    The fact that you’re passing CompareKeys to TComparer.Construct means that CompareKeys doesn’t have to be a normal function. Delphi 2009 introduced method references, which can refer to ordinary functions, methods, and anonymous methods. I assume TComparer.Construct constructs a method reference out of the ordinary function you give it. (I’m not sure why, though; I thought the compiler did that conversion automatically.)

    Suppose you have a three-argument function that receives a list and the two items to compare:

    function CompareKeys(List: TList<Integer>; Item1, Item2: Integer): Integer; 

    You should be able to pass an anonymous method something like this:

    KeyList.Sort(function(Item1, Item2: Integer): Integer;   begin     Result := CompareKeys(KeyList, Item1, Item2);   end); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume: 1) Multi-cpu environment 2) Process that gets interrupted, is the same process that
In a multi-threaded java program, what happens if a thread object T has been
I have a multi-threaded application that I'm debugging inside the IDE (Visual Studio 2008,
we have designed a multi threaded server that use linq to sql at each
Assume a multi-threaded application, with a signal handler defined in it. Now if a
Assume a multithreaded application scenario, in which every thread acquires some data (one or
Assume that we have two sets: A=(a_1,a_2,...,a_m) and B=(b_1,b_2,...,a_n) (Not necessarily of same size).
Assume I've declared a function (or class, doesn't matter) in a header file, which
My multi-threaded app segfaults on a call to PyImport_ImportModule(my_module) . The BT will be
Is it correct to assume that GetLastError (and variants) are per-thread or is it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.