Is there any cmdlet to manage threads, ie thread semaphore?
Possibly, without install any supplementary module...
Thank you in advance
Related
I am creating a web service that creates a huge amount of small java timer threads over (10k). I can only seem to create 2k timer threads before I get the OutOfMemoryError: unable to create new native thread. How do i solve this? I am using a macbook pro to run my Tomcat server on. I'v configured the ulimit (-u) max user processes to double what it used to be but I still get the same problem. What are my options, if any, to make this doable?
It's often a bad idea for web applications to start their own (few) threads, let alone 10K threads - and then "as timers"? Seriously? Don't go there.
What can you do?
Don't rely on the ability to create those threads.
Change your architecture! Use a scheduler library that has solved this problem already (e.g. Quartz or others).
If you don't want to use an external library (why wouldn't you?): Implement a single timer thread that executes the scheduled operations when they're due. Do not use a new thread for each scheduled operation
If you wanted to boil 100 eggs, would you buy 100 timers?
We are now using Task Parallel Library by implementing Task.Factory.StartNew(). Is there any way to check how many threads does the application spawn when executing the task ?
Currently we are running the application in dual core processor in the development environment.
TPL doesn't spawn any threads when executing a task unless you use a custom scheduler or you pass the TaskCreationOptions.LongRunning option. Even then, it is up to the TaskScheduler used to decide how to treat long-running tasks.
TPL schedules individual tasks to a threadpool for execution by the pool's threads. Each Thread has its own queue to reduce conflicts in multi-core machines. If a thread is too busy, the Framework uses some work-stealing magic to assign the task to an idle thread in the same thread pool.
Check How does the tpl use the CLR thread pool for a bit more info, and this post by Daniel Moth for details on work stealing.
I have found an application which requests process information using wmi queries (all threads and more info on each thread). I modified this application to determine the CPU usage per thread.
(if my application is called 'appy', then the threads are named 'appy/0', 'appy/1', ...)
My question: is there a way to easily identify these threads outside of an IDE or another debugging environment?
I know there is the NameThreadForDebugging method, but this isn't accessible outside the debugging environment.
Is there a way to assign your own thread id upon creating that thread?
Or is the only way to know who is who (the threads) by creating a dictionary and write that dictionary to a file so it is externally accessible.
Thanks in advance!
No, you cannot assign your own thread ID, the thread ID is assigned to a thread by the CreateThread function and cannot be changed during its lifetime. And as you said the only way to identify thread in the external application (not a debugger) is to share the thread identification with that application somehow.
However it's not necessary to share the information through a file, you can use a shared memory block for instance. It will be much more efficient than using files.
As the reference about thread ID you can take the remark by the GetCurrentThreadId function:
Until the thread terminates, the thread identifier uniquely identifies
the thread throughout the system.
In linux, in kvm environment, when a process in VM locks on some resource and is pre-empted, other processes of VM, which need that locked resource would spend time on spinlock. And the process would unlock the resource when it's allotted the PROCESSOR.
I would like to disable the scheduler from pre-emptying, until the process unlocks the resource. And this would reduce the cpu-time on spinlock.
How to achieve the above?? i.e.
How to findout if a process in VM has locked on some resource?
Then how
to inform scheduler to not to pre-empt the process until the resource is unlocked?
correct me if am wrong anywhere..
Thanks in advance..
Use spinlock_irq_save() call. It disables interrupts and preempting and locks a spinlock atomically.
See http://www.kernel.org/doc/Documentation/spinlocks.txt for use cases.
Is it possible that a program which does not kill its threads properly before exiting still be running some piece of code somewhere even though it has been killed in system monitor? I am running ubuntu in a non virtual environment. My application is made with QT, it contains QThreads, a main thread and concurent functions.
If you kill the process then you kill all its threads. The only cause for concern would be if your application had spawned multiple processes - if that is the case then you may still have code executing on the machine.
This is all very speculative though as I don't know what operating system you code is running on, whether or not your application runs in a virtual environment, etc. Environment-specific factors are very relevant to the discussion, can you share a bit more about your application?
It is not possible, all modern heaviliy used operating systems manage these resources quite tightly. Threads cannot run without a process... They are all brantches from the original thread.
I don't know of any OS that doesn't fully terminate all it's threads when you kill the processes, it's possible to spawn child processes that live on after the main process has exited but in the case of threads i'd say it's not possible.