Вы находитесь на странице: 1из 2

What is Multi-tasking ?

Ans.On one processor,multithreading is generally implemented by time slicing as


multitasking.
CPU switches between different software threads.
Parallel processing requires the context switching very often.

What is Multi-threading ?
Ans..Net has been designed from the startto support multi-threaded operation.
There are two main ways of multi-threading which .Net encourages:
ThreadStart delegates,
Thread Pool
a. ThreadStart delegates:A delegate is the .Net version of a type safe function
pointer.
All threads require an entry point to start execution.
By definition when a primary thread is created it always runs Main() as it's
entry point.
Any additional threads you create will need an explicitly defined entry point-a
pointer to the function where they begin execution.So threads always require a
delegate.
Delegates are often used in threading for other purposes too,mainly callbacks.
If you want a thread to report some information back such as completion
status,one possibility is to create a callback function that the thread can use.
The releationship between threads and delegates is secondary threads cannot just
call methods like the primary app thread,so a function pointer is needed instead
ans delegates act as a function pointers.

b. ThreadPool:Thread pooling is a form of multithreading in which tasks are added


to a queue and automaticallly started when threads are created.
The threading system in .Net supports a built-in thread pool that can be used in
many situations where you might expect to create your own threads.

What is a Thread ?
Ans. Thread is the smallest sequence of programmed instructions that can be managed
independently by a scheduler(Program written in OS).
Thread is a component of Process and both are managed and control by OS.
Multiple threads can exist within one process,executing concurrently and
shares resources such as memory,files,etc.
The threads of a process share its instructions and its context.

Explain the different level of priority.


Ans. Highest:The value of this priority is 4.
Above normal: The value of this priority is 3.
Normal: The value of this priority is 2.
BelowNormal:The value of this priority is 1.
Lowest: The value of this priority is 0.
How to find the reference current thread
Ans. A Thread class is responsible for creating and managing a thread in multi-
thread programming.It provides a property known as Current Thread to check the
current running thread.Or in other words, the value of t
indicates the current running thread.
Syntax:public static Thread CurrentThread{get;}
Return Value:This property returns a thread that represents the current
running thread.
// C# program to illustrate the
// use of CurrentThread property
using System;
using System.Threading;

class GFG {
// Main Method
static public void Main()
{
Thread thr;

// Get the reference of main Thread


// Using CurrentThread property
thr = Thread.CurrentThread;
thr.Name = "Main thread";
Console.WriteLine("Name of current running "+
"thread: {0}", thr.Name);
}
}

What's Thread.Sleep() in threading ?


Ans. It suspends the current thread for specified time.
How can we make a thread sleep for infinite period ?
Ans. Yes.

What's Thread.Join() in threading ?


Ans. Join(): method method is used to make all the calling thread to wait until the
main thread i.e. joined thread complete its work.
synchronization ?
Ans. The benefits of multi-threads in an application is that each thread executes
asynchronously.
Asynchronous nature of threads means that access to resources such as file
handles,network connections, and memory must be coordinated.
Two or more threads could access the same resources at the same time, each
unaware of the other's actions.The result is unpredictable data corruptions.
lock statement can be used to ensure that a block of code runs to completion
without interruption by other threads.

Вам также может понравиться