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 6082333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:16:40+00:00 2026-05-23T11:16:40+00:00

If you have a thread which calls a function, AFAIK it’s any global or

  • 0

If you have a thread which calls a function, AFAIK it’s any global or VCL component calls which make it not thread safe right?

So if your thread called a method like

procedure UpdateRow()
begin
    StringGrid1.AddRow(....);
end;

that is not thread safe.
however if you have a method like this

function ParseXML(const XML : String) : string;
var
    xml_parser : TXMLParser;
begin
    xml_parser := TXMLParser.create;
    ... do stuff
    result := xml_parser.something;
    xml_parser.free;
end;

that is thread safe, as long as the TXMLParser is not doing anything unthread safe.

But if two threads call that method at the same time, it wont throw an exception as they both create their own instance of TXMLParser right? They get their own copy. Is that correct?

Hope that makes sense 🙂

  • 1 1 Answer
  • 0 Views
  • 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. Editorial Team
    Editorial Team
    2026-05-23T11:16:40+00:00Added an answer on May 23, 2026 at 11:16 am

    Actually, it could be correct but doesn’t have to be. If TXMLParser also uses some global variable that’s not threadsafe, this code would not be threadsafe either! The use of global variables is discouraged but Delphi has quite a few build-in variables that might cause problems when they’re modied and read from different threads.
    The unit xmldom, for example, has two global variables: DefaultDOMVendor and DOMVendors. These aren’t really modified often, thus should be safe to use.
    The SysUtils unit also has a few global variables used for determining the current locale, date/time formats and whatever more. Those aren’t threadsafe either, although these too are almost never modified.
    Even third-party code might use global variables for all kinds of purposes. Some more modern code might even use class variables which would also be a kind of global variables and thus definitely not threadsafe, although the risks are based on the number of times the data is modified…

    Without a look in the code of TXmlParser it’s unclear if it’s threadsafe or not. If it uses a third-party DLL like Libxml2.dll then it becomes even more complicated since the handle for this DLL might be stored in a global variable, thus becoming unsafe.

    Then again, you said TXmlParser is threadsafe. To answer your question: your code would then be threadsafe too as long as the “Do stuff” part is threadsafe.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class which is not thread safe: class Foo { /* Abstract
I have a ajax function in index.php which calls on the page thread.php which
I have a function (internally uses ASIHTTPRequest) which calls a block with the result:
I have a thread which calls Popen to get a string back from a
I have a startup function that calls a function which returns a boolean based
I have a thread which handles all the HTTP Connections to the server and
I have thread exception handler which saves the exception stack trace and should close
I have the main thread from which I start a window using invokeLater .
I have one std::list<> container and these threads: One writer thread which adds elements
I have a parent thread (non-UI) which creates some child threads to do some

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.