"delphi: why vcl is not thread-safe? how can be?" Code Answer
Answers related to “delphi: why vcl is not thread-safe? how can be?”
- Is the PHP Intl extension thread safe?
- Trying to trace error for why email is not sending after webhook should be triggered in woocommerce
- Are global variables thread-safe in Flask? How do I share data between requests?
- Is local static variable initialization thread-safe in C++11?
- Is HttpSession thread safe, are set/get Attribute thread safe operations?
- Why are local variables thread safe in Java
- Is RestTemplate thread safe?
- Singleton instance declared as static variable of GetInstance method, is it thread-safe?
- I've heard i++ isn't thread safe, is ++i thread-safe?
- Must Spring MVC Classes be Thread-Safe
- Is java.sql.Connection thread safe?
- Is DbContext thread safe?
- Is errno thread-safe?
- Is malloc thread-safe?
- Is iterating ConcurrentHashMap values thread safe?
- Is a HashMap thread-safe for different keys?
- Is a volatile int in Java thread-safe?
- Is the += operator thread-safe in Python?
- Why does CreateProcess give error 193 (%1 is not a valid Win32 app)
- Is accept() thread-safe?
- How Can I Best Guess the Encoding when the BOM (Byte Order Mark) is Missing?
- How to implement a unmanaged thread-safe collection when I get this error: <mutex> is not supported when compiling...
- How to avoid issues when embedding a TForm in another TForm?
- Is .NET's StringBuilder thread-safe
- Is boost shared_ptr <XXX> thread safe?
- python dictionary is thread safe?
- Is stl vector concurrent read thread-safe?
- Why Servlets are not thread Safe?
- Is Cipher thread-safe?
- How to access c# WPF control in thread safe way?
- Not thread-safe Object publishing
- Is Sqlite Database instance thread safe
- Is Keras thread safe?
- Thread-safe in delphi
- Is int? thread safe?
- Is it thread safe to set Active Resource HTTP authentication on a per-user basis?
- Is static init thread-safe with VC2010?
- How can I guarantee that a type that doesn't implement Sync can actually be safely shared between threads?
- Why is List<T> not thread-safe?
- How to make a class Thread Safe [closed]
- Is List.iterator() thread-safe?
- Is this use of Parallel.ForEach() thread safe?
- Is Hibernate's session thread safe?
- Is using std::deque or std::priority_queue thread-safe?
- how to know what is NOT thread-safe in ruby?
- how to make an application thread safe?
- Is PHP thread-safe?
- Why is std::queue not thread-safe?
- Is LinkedList thread-safe when I'm accessing it with offer and poll exclusively?
- If arrays are value types and therefore get copied, then how are they not thread safe?
- Delphi - Is TClientDataset Thread Safe?
- Is this use of a static queue thread-safe?
- Is ofstream thread safe?
- Is SqlConnection / SqlCommand thread safe?
- How can I make a a dialog box happen directly after my app's main form is visible?
- Is javax.servlet.ServletContext set/getAttribute thread safe?
- C#: How can I make an IEnumerable<T> thread safe?
- Which features make a class to be thread-safe?
- Is MemoryCache.Set() thread-safe?
- How is BackgroundWorker.CancellationPending thread-safe?
- Is Joda-Time DateTimeFormatter class thread safe?
- How I can change the color of a TPanel with the VCL Styles enabled?
- How can I tell if a Delphi control is currently visible?
- How to load images from disk in background (multiple threads) [AKA: TBitmap is not thread-safe]
- Is memcpy process-safe?
- In Delphi, is TDataSet thread safe?
- How to make a static Calendar thread safe
- Delphi - Why does ExplicitWidth and ExplicitHeight keep appearing in .DFM files and what is it?
- Is a readonly field in C# thread safe?
- Is ||= in Ruby thread safe?
- NSMutableArray is thread safe?
- How do I add support for actions in my component
- Is Contains thread safe in HashSet<T>
- Creating a new component by combining two controls (TEdit and TTrackBar) in Delphi VCL
- How to create a delphi form containing multiple 'child' forms that can be moved/sized and show activated
- Is the scanner in java not thread safe?
- What is a thread-safe way to read/write a C# property in a class?
- Is epoll thread-safe?
- Which language elements can be annotated using attributes language feature of Delphi?
- Is get_or_create() thread safe
- Is DocumentBuilder.parse() thread safe?
- Are Delphi simple types thread safe?
- CircularBuffer highly efficient implementation (both thread-safe and not thread-safe) [closed]
- How to iterate over a container in a thread-safe way?
- How can I make a form that is not disabled when another form is shown modally?
- UIKit drawing is thread safe: how do you get a graphics context?
- What does “ StringBuilders are not thread-safe” mean?
- Why instance variable in Servlet is not thread-safe
- Is using `std::get<I>` on a `std::tuple` guaranteed to be thread-safe for different values of `I`?
- Is qDebug() thread-safe?
- Is this non-locked TryGetValue() dictionary access thread-safe?
- Is Django middleware thread safe?
- java.text.SimpleDateFormat not thread safe
- Is a Spring Data (JPA) Repository thread-safe? (aka is SimpleJpaRepository thread safe)
- why is i++ not thread safe on a single core machine?
- Delphi non visual TTree implementation
- Is Ruby's stdlib Logger class thread-safe?
- Why the exception is not caught by the try… except end;?
- Why is reading not thread-safe?
- Is Java socket multi-thread safe?
- is std::queue thread safe with producer and multiple consumers
- Is std::regex thread safe?
- How to use an AppDomain to limit a static class' scope for thread-safe use?
- Is it memory safe to provide an object as a function result?
- how can delphi 'string' literals be more than 255?
- How to make a variable thread-safe
- Program icon looks curious in the title bar when using a VCL style
- INDY 10 TCP Server - Combine with non thread safe VCL Code
- Why System.Windows.Forms.Control MousePosition property can be read, but Location not?
- How can I test if an unknown Delphi RTTI TValue reflects an object that is ANY type of generic TList<> (or at least...
- is newKieSession thread-safe?
- Is C read() Thread Safe?
- Is CryptGenRandom() thread-safe?
- Why Canvas is “hidden” in all VCL controls?
- How to make a single component support both VCL and FMX?
- Disabling TButton issue on a VCL styled form
- Is the Microsoft Enterprise Library 5.0 Logging Application Block thread safe?
- Delphi DLL - thread safe
- How can I implement a thread-safe list wrapper in Delphi?
- IS ResultSet thread safe
- Delphi IDE is not visible
- How can get my form to be on top of everything all the time?
- Delphi 7 - how to use Inputbox
- Is it thread-safe to read an instance variable while calling a setter from another thread?
- Why cant a thread that is not the UI thread access the view?
- Android In-app product that is not consumable, but several can be purchased
- Is Ruby Thread-Safe by default?
- What is the definition of a thread safe function according to the C++11 (Language/Library) Standard?
- What is the Best Practice for thread-safe access to controls
- Why is not Swing “thread safe”? [closed]
- Is the != check thread safe?
- Why is this class not thread safe?
- Is NSUserDefault thread safe?
- Why aren't classes like BindingList or ObservableCollection thread-safe?
- What “type of” declaration represents in Delphi and how can it be used
- Is extending a Python list (e.g. l += [1]) guaranteed to be thread-safe?
- Is working with the Session thread-safe?
- is boost::property_tree::ptree thread safe?
- Is autoload thread-safe in Ruby 1.9?
- Is there any Delphi XE2 styles gallery?
- What is meant by CoreData is not thread safe?
- how can i see how much of the stack space is currently used in my delphi app?
- Is the “switch” statement evaluation thread-safe?
- Is the List<T>.AddRange() thread safe?
- Is CreateDirectory() in C# thread-safe?
- Is it thread safe to reset and copy shared_ptr simultaneously?
- In a Thread Safe Singleton does the return have to be inside the synchronized block
- Is this stored procedure thread-safe? (or whatever the equiv is on SQL Server)
- Delphi XE2 VCL styles, changing window Icon doesn't update on the caption bar until RecreateWnd
- Is returning an IEnumerable<> thread-safe?
- ConcurrentDictionary TryGetValue vs []. Is [] still thread-safe?
- How safe is MongoDB's safe mode on inserts?
- Is the C# '??' operator thread safe?
- Is there an open source thread safe C++ object pool implementation? [closed]
- How can I create alpha blended icon/cursor (indirect) from the TBitmap instance of 32 bpp w/o making an temporary...
- Why A single Jedis instance is not threadsafe?
- Is this a valid, lazy, thread-safe Singleton implementation for C#?
- is this GCD implemented getter setter thread safe and work better than @synchronized? objc
- Why is the standard C# event invocation pattern thread-safe without a memory barrier or cache invalidation? What...
- How to easy make this counter property thread safe?
- Is C3P0 thread-safe?
- How can I temporarily disable the “return value might be undefined” warning?
- Is Parallel.ForEach in ConcurrentBag<T> thread safe
- is sprintf thread safe?
- Is this use of the generic List thread safe
- Is VclStyle Bug ? TProgressBar.Style := pbstMarQuee Does not work
- C# Is it thread safe to subscribe Same event handler for all Objects
- Is MSMQ thread safe?
- Why should we make a SessionScoped ManagedBean thread safe in JSF?
- Is Spring mongoTemplate thread safe?
- Qt is not exception safe. How does this impact C++ code?
- Is it thread safe to call async_send and async_receive at the same time?
- Delphi XE2 styles painting
- TEmbeddedWB/TWebbrowser: window.external is an empty object but can call functions, why is it 'empty' in the first...
- How do I fix Delphi Prism ASP.NET error: “Parser Error Message: 'Oxygene' is not a supported language”
- Is putStrLn thread-safe?
- is DatagramSocket.send thread safe?
- In Delphi, how can you check if an IInterface reference implements a derived but not explicitly-supported interface?
- Is the null coalescing operator (??) in C# thread-safe?
- How can I declare an array property?
- How can Delphi records be initialized automatically?
- Is DWScript thread-safe?
- Is python zipfile thread-safe?
- Is Kotlin `?.let` thread-safe?
- How to know if a Java SE class or method is thread safe?
- Java ConcurrentHashMap not thread safe.. wth?
- Is the ternary operator (?:) thread safe in C#?
- Is `asprintf` thread-safe?
- System.exit is not thread-safe on Linux?
- Function local static function-object that's initialized by lambda, thread-safe or not?
- How to use default value in the builder pattern if that value is not passed and also make thread safe?
- what are pitfalls of making UnityContainer not thread safe?
- Why isn't Darwin's strtod thread safe?
- Instance constructor sets a static member, is it thread safe?
- Is createTempFile thread-safe?
- Why Jpeg is accepted in the uses clause in some projects and in others vcl.imaging.jpeg is required?
- How to make java class thread safe?
- multithreading: Why aren't generators thread-safe? What happens when it is shared among threads?
- Where is the sizing data of TOpenDialog stored and how can this be reset?
- Why are atomic operations considered thread-safe?
- Delphi XE2 VCL styles, remove a style or disable a class skinning from a TLabel
- How to correctly use VAVR collections to be thread safe?
- How to make this thread-safe
- How to change color of the scrollbar in SynMemo with VCL styles
- Is AndroidHttpClient thread safe
- Is the following utility class thread-safe?
- Is AtomicInteger.incrementAndGet thread safe?
- How to print TPanel contents?
- Is this example thread safe?
- How can one implement a thread-safe wrapper to maps in Go by locking?
- Is it thread safe to read a form controls value (but not change it) without using Invoke/BeginInvoke from another...
- delphi variable value is changing at thread in a loop
- Reduce CPU time spent in VCL
- How to have both VCL and FMX in one application?
- Is that StringBuilder variable thread safe in this code?
- How can I test that ConcurrentHashMap is truly thread-safe?
- Inno Setup: change the setup language while setup is running
- Right to left ComboBox in Delphi XE2 with styles
- How to make reading this instance primitive thread-safe without locking?
- Global, thread safe, cookies manager with Indy
- When creating thread safe reads in Swift, why is a variable create outside the concurrent queue?
- can some one confirm if this is a thread safe implementation of singleton
- How to install JVCL packages if the installer failed when I ran it as a non-Administrator User
- Thread-safe way to increment and return an integer in Delphi
- Proving the following code not thread safe
- Is .NET System.Net.CookieContainer thread safe?
- How to increment (add value to) decimal in a thread-safe way?
- Is python's "in" language construct thread-safe for lists?
- Is this a thread safe way to initialize a [ThreadStatic]?
- Delphi - Why is TObject.InitInstance public?
- Is this combination of ConcurrentDictionary and ConcurrentQueue thread-safe?
- how to make a transparent form when a VCL Style is enabled?
- Is KeyFactory thread-safe?
- Java: is Exception class thread-safe?
- Is this html helper thread safe?
- Delphi: How to find and fix an EOutOfMemory Error?
- How can one break this (non?) thread safe object?
- Is closesocket thread safe?
- Why may thread_local not be applied to non-static data members and how to implement thread-local non-static data...
- How can I apply Delphi XE2 skins to forms in a DLL?
- Modifying VCL Component CODE
- Is NotifyPropertyChanged thread safe?
- Is this null pointer exception in TreeMap due to concurrent access?
- Why Terminated property of thread is set?
- Microsoft Enterprise Library Caching Application Block not thread safe?
- Do PRNG need to be thread safe?
- Is this using of dictionary thread-safe or not?
- How to make a shared resource thread-safe when using dependency injection?
- How can I add a border to every form in my application without modifying each form's code?
- Delphi Xe2 VCL style and webbrowser
Only authorized users can answer the Search term. Please sign in first, or register a free account.
what, precisely, does "thread-safe" mean to you? what about someone else? every time i see this brought up, it ends up boiling down to this: "i want vcl to be thread-safe so i don't have to think about threading and synchronization issues. i want to write my code as if it is still single-threaded."
no matter how much work went into making vcl so-called "thread-safe", there will always be situations where you can get into trouble. how would you go about making it thread-safe? i don't say this to be combative, rather i merely want to demonstrate that it is not a simple problem with a simple, "works-in-all-cases" solution. to highlight this, let's look at some potential "solutions."
the simplest and most direct approach i see is each component has some kind of "lock", say a mutex or critical section. every method on the component grabs the lock on entry and then releases the lock just prior to exit. let's continue down this path with a thought experiment. consider how windows processes messages:
main thread obtains a message from the message queue and then dispatches it to the appropriate wndproc. this message is then routed to the appropriate twincontrol component. since the component has a "lock", as the message is routed to the appropriate message handler on the component, the lock is acquired. so far so good.
now take the proverbial button-click message processing. the onclick message handler is now called which will most likely be a method on the owning tform. since the tform descendant is also a twincontrol component, the tform's lock is now acquired while the onclick handler is processed. now the button component is locked and the tform component is also locked.
continuing on this line of thinking, suppose the onclick handler now wants add an item to a listbox, listview, or some other visual list or grid component. now suppose some other thread (not the main ui thread) is already in the midst of accessing this same component. once a method is called on the list from the ui thread it will attempt to acquire the lock, which it cannot since the other thread is currently holding it. as long as the non-ui thread doesn't hold that lock for very long, the ui thread will only block for a brief period.
so far so good, right? now suppose, that while the non-ui thread is holding the list control's lock, a notification event is called. since, it will most likely be a method on the owning tform, upon entry to the event handler, the code will attempt to acquire the lock for the tform.
do you see the problem? remember the button onclick handler? it already has the tform lock in the ui thread! it is now blocked waiting for the lock on the list control, which the non-ui thread owns. this is a classic dead-lock. thread a holds lock a and attempts to acquire lock b which is held by thread b. thread b is at the same time attempting to acquire lock a.
clearly, if every control/component has a lock that is automatically acquired and released for every method isn't a solution. what if we left the locking up to the user? do you see how that also doesn't solve the problem either? how can you be certain that all the code you have (including any third-party components) properly locks/unlocks the controls/components? how does this keep the above scenario from happening?
what about a single shared lock for the whole of vcl? in this scenario, for each message that is processed, the lock is acquired while the message is processed regardless of what component the message is routed to. again, how does this solve a similar scenario i described above? what if the user's code added other locks for synchronization with other non-ui threads? even the simple act of blocking until a non-ui thread terminates can cause a dead lock if it is done while the ui thread holds the vcl lock.
what about non-ui components? database, serial, network, containers, etc...? how should they be handled?
as excellently explained by the other answers, windows already does a pretty decent job of properly segregating ui message processing to only the thread on which each hwnd is created. in fact, learning precisely how windows works in this regard will go a long way to understanding how you can write your code to work with windows and vcl in a manner that avoids most of the pitfalls i highlighted above. the bottom line is writing multi-threaded code is difficult, requires a rather drastic mental shift, and lots of practice. read as much as you can on multi-threading from as many sources as possible. learn and understand as many coding examples of "thread-safe" code as you can, in any language.
hopefully this was informative.