The question stands by itself, either way, the stardard hash-table in common-lisp is not thread-safe, is there any thread-safe version implemented in a readily available package in quicklisp?
Related
I want to understand how to work with unmanaged resources and when I need the SafeHandle class. What can be the problem statement when you can say: "Oh, here I need the SafeHandle class!"?
I would be grateful for links to articles, examples, explanations
I think MSDN is pretty clear in definition:
The SafeHandle class provides critical finalization of handle
resources, preventing handles from being reclaimed prematurely by
garbage collection and from being recycled by Windows to reference
unintended unmanaged objects. Before the .NET Framework version 2.0,
all operating system handles could only be encapsulated in the IntPtr
managed wrapper object.
The SafeHandle class contains a finalizer that ensures that the handle
is closed and is guaranteed to run, even during unexpected AppDomain
unloads when a host may not trust the consistency of the state of the
AppDomain.
For more information about the benefits of using a SafeHandle, see
Safe Handles and Critical Finalization.
This class is abstract because you cannot create a generic handle. To
implement SafeHandle, you must create a derived class. To create
SafeHandle derived classes, you must know how to create and free an
operating system handle. This process is different for different
handle types because some use CloseHandle, while others use more
specific methods such as UnmapViewOfFile or FindClose. For this
reason, you must create a derived class of SafeHandle for each
operating system handle type; such as MySafeRegistryHandle,
MySafeFileHandle, and MySpecialSafeFileHandle. Some of these derived
classes are prewritten and provided for you in the
Microsoft.Win32.SafeHandles namespace.
Rust seems to have 3 different types of tasks,
std::task
core::task
tokio::task
Why do these three tasks exist?
Those are modules, so the fact that they all coexist and have the same name doesn't really imply anything. Any arbitrary crate can create a task module (or type or trait or...). That's why most programming languages have namespaces to start with — so we can have name collisions
std::task is core::task, re-exported under a different name. This contains the building blocks for creating futures themselves and the executors that drive them. A very small handful of people will need to use these types.
tokio::task allows creating Tokio tasks: "asynchronous green-threads". These are the semantic equivalent of threads for an asynchronous world. See the Tokio website's section on spawning tasks for more detail.
async_std::task is the same thing but for a different executor. async-std tasks are distinct from Tokio tasks and are not interchangeable.
futures::task is kind of a mish-mash between the standard library's module and those of the executors. This is because of its history — the futures crate was the implementation of futures before they were moved into the standard library. Now it contains a re-export of the standard library's types plus some further tools for creating an executor as well as traits for spawning tasks on the executor provided by the futures library.
See also:
What is the difference between `alloc::rc::Rc` and `std::rc::Rc`?
std::ops::Add or core::ops::Add?
How do I execute an async/await function without using any external dependencies?
Qore stream documentation (https://qoretechnologies.com/manual/qorus/latest/qore/lang/html/class_qore_1_1_output_stream.html) says that stream instance cannot be called from other thread than the object has been created (and I really see hardcoded check snippet if (tid != gettid()) then raise exception. It seems rather as huge limitation because even locking won't help.
What is supposed solution when I need use a stream object from more threads ?
I can imagine extra "stream" thread and a queue as only solution.
Iterators and streams both are limited to single-threaded use by design for performance reasons and also because no realistic use case for using streams from multiple threads could be identified with the built-in stream objects when the design and implementation of Qore streams was done.
You can implement your own streams that support multi-threaded use because the minimal internal C++ implementations of the abstract base classes, InputStream and OutputStream, do not contain any limitations on multi-threaded usage.
If you really need multi-threaded support in builtin streams, then Qore could be extended to allow for the appropriate locking to be implemented in subclasses for example.
In my project, I used QHttpResponseHeader in Qt4.8.6, but it became obsolete and it is not
available anymore in Qt5. What is its equivalent class in Qt5?
There is an equivalent already available in Qt4.8 : look at the QNetworkReply class, particularly the header() and rawHeader() functions. It should be what you are looking for.
A bit of explanation : QNetworkAccessManager is the class which allows you to send and receive requests. It is much more flexible and not limited to a single protocol, in contrast to QHttp/QFtp. Before, you had to decide on the application level which protocol to use, and now you only pass an URL to the QNetworkAccessManager, it will manage the rest.
I have several threads each of which loads the same plugin using QPluginLoader::staticInstances() call in constructor. Is it necessary to protect operating with plugin with mutexes / semaphores and so on?
the functions of QPluginLoader are reentrant and you are operating on the same objects; so yes you need to synchronize on individual QPluginLoader objects at the very least.
instance() will also return a shared object which needs to be access in a thread-safe manner