Scheduling the created thread immediately - multithreading

i am using PsCreateSystemThread() for creating a thread. But it is not getting scheduled immediately. How can i force that thread schedule immediately after the creation of the thread.

Scheduling can be forced by KeSetPriorityThread and/or KeSetBasePriorityThread.

Related

Daemon And Non-Daemon Threads In Java

JVM in Java is responsible to create a Non-Daemon Thread when executing a Java program. Is it correct?
If so, who is responsible to create Daemon Threads in Java?
Programmers and JVM both create Non-Daemon Threads? Is it correct?
Looking for a clear explanation.
Thanks in Advance.
It doesn’t matter whether “the JVM” or “the programmer” started a thread. A thread is a daemon thread when setDaemon(true) has been called on it before starting or a daemon thread created the thread without calling setDaemon. That’s it.
The documentation of Thread also says:
When a Java Virtual Machine starts up, there is usually a single non-daemon thread (which typically calls the method named main of some designated class).
There is no responsibility to create daemon threads. Marking a thread as daemon has only one implication which the documentation continues to explain:
The Java Virtual Machine continues to execute threads until either of the following occurs:
The exit method of class Runtime has been called and the security manager has permitted the exit operation to take place.
All threads that are not daemon threads have died, either by returning from the call to the run method or by throwing an exception that propagates beyond the run method.
So, that’s the only implication; the existence of a non-daemon thread may prevent the JVM from terminating automatically, whereas threads marked as daemon do not.

Synchronization: Wake up a thread when all other threads have left

Here's the scenario:
When my application is shutting down I wish to start a disposing thread but it must sleep straight away. I want all the running threads enter a cleanup section. Once all of those threads have finished their job and left the section, I want the disposing section wake up and finaliaze the shut down process.
Which synchronization mechanism should I use, Mutex, Monitor, or Semaphore? and How?
Thanks.

what's the state of the process when it is multithread?

The state of a process is defined by the current activity of that process.
new
running
waiting
ready
terminated
So if it is multi thread, has more than one state?
Yes. Each thread of execution can be ready to run, running, or blocked. Other possible states exist on some platforms as well.

Windows service onstop will kill the thread?

I have a windows service where I create a thread for doing the background process. So once the thread finishes the task, do I need to call the service ‘stop’ event to make the service stop? (like this.stop() in code)
I didn’t clearly understand why it’s asking to not write code in onstart event and asked to create a thread. Is it because the service will stop after a particular time? Will it cause my thread also to stop, when the service ends? Because I don’t need that. The thread should handle a long running process; I need the thread not killed until it finishes the task.

In linux scheduler, does it track the current sleeping task or killed task?

I know when a task runs, it is enqueued into the running queue. When it sleeps, it is dequeued from the running queue. But is there a queue for sleeping tasks? I didn't see this in the source code.
And even if I were to create such a queue, how can I know when a task is killed and should be removed from the sleeping queue?
Can anyone give me a hint? Thanks,
In Linux blocked (sleeping) tasks are queued in a structure called a wait queue. There exists a wait queue per event (or object) that can be waited upon.
So, there is no single wait queue (or per core), but per event wait queue. The kernel code explicitly puts tasks on the wait queue and removes them when the specific event arrives. See wait_event() kernel API for example.

Resources