vs-threading | xplat library | Architecture library
kandi X-RAY | vs-threading Summary
kandi X-RAY | vs-threading Summary
[Join the chat at
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of vs-threading
vs-threading Key Features
vs-threading Examples and Code Snippets
Community Discussions
Trending Discussions on vs-threading
QUESTION
In a constructor that gets dependency injected I need to make an asynchronous call.
(This was not originally my code. It gets used in many places. I don't think it's relevant, but this is part of an implementation for FluentValidation.AbstractValidator
. The implementation of ConfigureValidationRulesAsync()
is in the base class.)
ANSWER
Answered 2022-Feb-14 at 13:06Below is the best set of conclusions that I could derive from all the comments on the question.
Point #1: Injection Constructors should be simpleInjection constructors should be simple, and in the context of Fluent Validation, the MustAsync method should help to simplify asynchronous validation.
Point #2: Warning not applicable to .NET CoreWhile I can use JoinableTaskFactory
, I should not be getting this warning, because the problem it is trying to solve is not applicable to .NET Core.
Below is the description from the documentation for JoinableTaskFactory
. It applies to situations where joining threads to the main thread could cause deadlocks.
A factory for starting asynchronous tasks that can mitigate deadlocks when the tasks require the Main thread of an application and the Main thread may itself be blocking on the completion of a task.
Thus, one can safely ignore the warning in the cases where it is simply not possible to rewrite the code. (Note the use of Task.Run()
, which is the recommended way to launch a compute-bound task as of .NET Framework 4.5.)
QUESTION
Let's consider a simple case - I'm running a .net5 console app on Windows. If I grab traces via PerfView /threadTime collect like described in here then I get to see BLOCKED_TIME metric in Thread Time Stacks tab. How should I run dotnet-trace command to get the same metric in Perfview? I've tried to play with the verbosity level but no luck so far.
...ANSWER
Answered 2021-Oct-29 at 14:10In short, you can't :(
Dotnet-trace uses a sampling profiler implemented in the .NET runtime. The profiler runs in a separate thread in the application and collects call stack frames of managed threads every few milliseconds. In contrary to most CPU profilers, it collects call stacks even for threads that are waiting. So, by looking at call stacks, you could estimate the waiting time for a managed thread. For example, in the picture below, we may see a managed thread waiting for about 686 ms on a ManualResetEvent.
Of course, this is only an estimate and depends on the sampling interval. You may also enable the CLR ThreadPool events and/or the TplEventSource provider to get events describing the inner-working of the thread pool and TPL.
Now, for the BLOCKED_TIME
metric in PerfView. It is based on Context Switch ETW events. You enable them with the 'Thread Time' checkbox in the PerfView collection dialog:
These events are emitted by the system scheduler/dispatcher when a new thread starts running on a CPU. They allow us to measure threads' waiting/running times accurately, but they are also very voluminous.
QUESTION
I know fork process does not share memory, and threads do, but then how can forked processes communicate one another?
Here is example, where one version with thread is commented out (and that version will end), and the other version with fork will never ends. The code is relying on the global variable done
:
ANSWER
Answered 2020-Dec-15 at 15:23When you execute a fork
you create a copy of the process you are executing with a different PID
the variables declared before the fork()
execution will appear in both processes. fork
returns 0
in the "child" process and returns the pid
of the "child" process in the "parent" process (with a switch
, you can control the behavior of both processes).
If you want to communicate different processes created by fork()
you can declare BEFORE an array of file descriptors such as int fd[2]
and execute pipe(fd)
. If the result of pipe
isn't -1
, means you have created two "cables" where you can write
or read
information.
Here you can see an example on how this can work
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install vs-threading
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page