Threads

Introduction (เคชเคฐเคฟเคšเคฏ)

เค…เคฌ เคคเค• เคนเคฎเคจเฅ‡ process เค•เฅ‡ เคฌเคพเคฐเฅ‡ เคฎเฅ‡เค‚ เคชเคขเคผเคพเฅค
เคฒเฅ‡เค•เคฟเคจ เค•เคˆ เคฌเคพเคฐ เคเค• เคนเฅ€ process เค•เฅ‡ เค…เค‚เคฆเคฐ เค•เคˆ เค›เฅ‹เคŸเฅ‡-เค›เฅ‹เคŸเฅ‡ tasks เคเค• เคธเคพเคฅ เคšเคฒเคคเฅ‡ เคนเฅˆเค‚เฅค
เค‡เคจเฅเคนเฅ€เค‚ tasks เค•เฅ‹ threads เค•เคนเคพ เคœเคพเคคเคพ เคนเฅˆเฅค

Example เค•เฅ‡ เคฒเคฟเค browser เค•เฅ‹ เคธเคฎเคเฅ‹:

  • เคเค• tab open เคนเฅˆ
  • เคเค• file download เคนเฅ‹ เคฐเคนเฅ€ เคนเฅˆ
  • เคเค• page scroll เคนเฅ‹ เคฐเคนเคพ เคนเฅˆ

เคฏเฅ‡ เค•เคพเคฎ เคเค• เคนเฅ€ process เค•เฅ‡ เค…เค‚เคฆเคฐ เค…เคฒเค—-เค…เคฒเค— threads เค•เฅ€ เคฎเคฆเคฆ เคธเฅ‡ เคนเฅ‹ เคธเค•เคคเฅ‡ เคนเฅˆเค‚เฅค

Thread เค•เฅเคฏเคพ เคนเฅ‹เคคเคพ เคนเฅˆ

Thread process เค•เคพ เคธเคฌเคธเฅ‡ เค›เฅ‹เคŸเคพ execution unit เคนเฅ‹เคคเคพ เคนเฅˆเฅค

เคœเคฌ process run เค•เคฐเคคเคพ เคนเฅˆ, เคคเฅ‹ เค‰เคธเค•เฅ‡ เค…เค‚เคฆเคฐ เคเค• เคฏเคพ เคเค• เคธเฅ‡ เค…เคงเคฟเค• threads เคนเฅ‹ เคธเค•เคคเฅ‡ เคนเฅˆเค‚เฅค
เคนเคฐ thread เค…เคชเคจเคพ เค…เคฒเค— execution flow เคฐเค–เคคเคพ เคนเฅˆเฅค

Simple Definition

Thread เคเค• lightweight process เคนเฅˆ, เคœเฅ‹ process เค•เฅ‡ เค…เค‚เคฆเคฐ independently execute เค•เคฐ เคธเค•เคคเคพ เคนเฅˆเฅค

Thread เค•เฅ‹ lightweight process เค•เฅเคฏเฅ‹เค‚ เค•เคนเคคเฅ‡ เคนเฅˆเค‚

Process create เค•เคฐเคจเคพ heavy เค•เคพเคฎ เคนเฅ‹เคคเคพ เคนเฅˆ, เค•เฅเคฏเฅ‹เค‚เค•เคฟ เค‰เคธเค•เฅ‡ เคฒเคฟเค เค…เคฒเค— memory space, resources เค”เคฐ control information เคšเคพเคนเคฟเค เคนเฅ‹เคคเฅ€ เคนเฅˆเฅค

เคฒเฅ‡เค•เคฟเคจ thread process เค•เฅ‡ resources เค•เฅ‹ share เค•เคฐเคคเคพ เคนเฅˆ, เค‡เคธเคฒเคฟเค:

  • thread create เค•เคฐเคจเคพ เค†เคธเคพเคจ เคนเฅ‹เคคเคพ เคนเฅˆ
  • thread switching fast เคนเฅ‹เคคเฅ€ เคนเฅˆ
  • system performance เคฌเฅ‡เคนเคคเคฐ เคนเฅ‹เคคเฅ€ เคนเฅˆ

Process aur Thread เคฎเฅ‡เค‚ เค…เค‚เคคเคฐ

BasisProcessThread
MeaningRunning programProcess เค•เคพ execution unit
Memoryเค…เคฒเค— memory spaceShared memory space
Resourceเค…เคฒเค— resourcesProcess ke resources share เค•เคฐเคคเคพ เคนเฅˆ
CreationSlowFast
SwitchingMore timeLess time
Communicationเคฎเฅเคถเฅเค•เคฟเคฒเค†เคธเคพเคจ

Thread Structure

เคเค• process เค•เฅ‡ เค…เค‚เคฆเคฐ เค•เฅเค› เคšเฅ€เคœเฅ‡เค‚ shared เคนเฅ‹เคคเฅ€ เคนเฅˆเค‚ เค”เคฐ เค•เฅเค› เคšเฅ€เคœเฅ‡เค‚ เคนเคฐ thread เค•เฅ€ เค…เคชเคจเฅ€ เคนเฅ‹เคคเฅ€ เคนเฅˆเค‚เฅค

Shared by all threads

  • Code section
  • Data section
  • Open files
  • Process resources

Separate for each thread

  • Program Counter
  • Registers
  • Stack

เค‡เคธเค•เคพ เคฎเคคเคฒเคฌ เคฏเคน เคนเฅˆ เค•เคฟ เคธเคญเฅ€ threads เคเค• เคนเฅ€ process เค•เฅ‡ data ko use เค•เคฐ เคธเค•เคคเฅ‡ เคนเฅˆเค‚, เคฒเฅ‡เค•เคฟเคจ เคนเคฐ thread เค•เคพ execution path เค…เคฒเค— เคนเฅ‹เคคเคพ เคนเฅˆเฅค

Single Threaded aur Multithreaded Process

Single Threaded Process

เค‡เคธเคฎเฅ‡เค‚ process เค•เฅ‡ เค…เค‚เคฆเคฐ เค•เฅ‡เคตเคฒ เคเค• เคนเฅ€ thread เคนเฅ‹เคคเคพ เคนเฅˆเฅค
เคเค• เคธเคฎเคฏ เคฎเฅ‡เค‚ เคเค• เคนเฅ€ เค•เคพเคฎ properly execute เคนเฅ‹เคคเคพ เคนเฅˆเฅค

Example:
เค•เฅ‹เคˆ simple calculator app

Multithreaded Process

เค‡เคธเคฎเฅ‡เค‚ process เค•เฅ‡ เค…เค‚เคฆเคฐ เค•เคˆ threads เคนเฅ‹เคคเฅ‡ เคนเฅˆเค‚เฅค
เคเค• เคนเฅ€ process เคเค• เคธเคพเคฅ multiple tasks handle เค•เคฐ เคธเค•เคคเคพ เคนเฅˆเฅค

Example:
Browser, media player, online editor

Multithreading เค•เฅเคฏเคพ เคนเฅ‹เคคเคพ เคนเฅˆ

เคœเคฌ เคเค• process เค•เฅ‡ เค…เค‚เคฆเคฐ multiple threads เคนเฅ‹เคคเฅ‡ เคนเฅˆเค‚ เค”เคฐ เคตเฅ‡ เค…เคฒเค—-เค…เคฒเค— tasks perform เค•เคฐเคคเฅ‡ เคนเฅˆเค‚, เคคเฅ‹ เค‰เคธเฅ‡ multithreading เค•เคนเคคเฅ‡ เคนเฅˆเค‚เฅค

เคฏเคน technique modern operating systems เคฎเฅ‡เค‚ เคฌเคนเฅเคค useful เคนเฅˆ เค•เฅเคฏเฅ‹เค‚เค•เคฟ เค‡เคธเคธเฅ‡ system responsive เคฌเคจเคคเคพ เคนเฅˆเฅค

Types of Threads

1. User-Level Threads

เคฏเฅ‡ threads user space เคฎเฅ‡เค‚ manage เคนเฅ‹เคคเฅ‡ เคนเฅˆเค‚เฅค
Operating System directly เค‡เคจเฅเคนเฅ‡เค‚ manage เคจเคนเฅ€เค‚ เค•เคฐเคคเคพเฅค

Features

  • Fast creation
  • Fast switching
  • OS เค•เฅ‹ direct เคœเคพเคจเค•เคพเคฐเฅ€ เคจเคนเฅ€เค‚ เคนเฅ‹เคคเฅ€

Problem

เค…เค—เคฐ เคเค• thread block เคนเฅ‹ เคœเคพเค, เคคเฅ‹ เคฌเคพเค•เฅ€ threads เคญเฅ€ เคฐเฅเค• เคธเค•เคคเฅ‡ เคนเฅˆเค‚

2. Kernel-Level Threads

เคฏเฅ‡ threads Operating System เคฆเฅเคตเคพเคฐเคพ manage เค•เคฟเค เคœเคพเคคเฅ‡ เคนเฅˆเค‚เฅค

Features

  • Better control
  • True parallelism possible
  • OS scheduling เค•เคฐเคคเคพ เคนเฅˆ

Problem

เค‡เคจเค•เคพ creation เค”เคฐ switching เคฅเฅ‹เคกเคผเคพ slow เคนเฅ‹ เคธเค•เคคเคพ เคนเฅˆ

Threads เค•เฅ‡ เคซเคพเคฏเคฆเฅ‡

1. Responsiveness

Application เคœเคฒเฅเคฆเฅ€ response เคฆเฅ‡เคคเคพ เคนเฅˆ

Example:
Download เคšเคฒเคคเฅ‡ เคนเฅเค เคญเฅ€ browser open เคฐเคนเคคเคพ เคนเฅˆ

2. Resource Sharing

เคธเคญเฅ€ threads same memory เค”เคฐ resources เค•เฅ‹ share เค•เคฐเคคเฅ‡ เคนเฅˆเค‚

3. Economy

Threads เคฌเคจเคพเคจเคพ process เค•เฅ€ เคคเฅเคฒเคจเคพ เคฎเฅ‡เค‚ เค•เคฎ costly เคนเฅ‹เคคเคพ เคนเฅˆ

4. Better CPU Utilization

Multiple tasks efficiently run เคนเฅ‹ เคธเค•เคคเฅ‡ เคนเฅˆเค‚

5. Parallelism

Multi-core system เคฎเฅ‡เค‚ multiple threads parallel run เค•เคฐ เคธเค•เคคเฅ‡ เคนเฅˆเค‚

Threads เค•เฅ€ เค•เคฎเคฟเคฏเคพเค

1. Synchronization Problem

Shared data เคนเฅ‹เคจเฅ‡ เค•เฅ€ เคตเคœเคน เคธเฅ‡ conflict เคนเฅ‹ เคธเค•เคคเคพ เคนเฅˆ

2. Debugging Difficult

Multithreaded programs เค•เฅ‹ debug เค•เคฐเคจเคพ เคฎเฅเคถเฅเค•เคฟเคฒ เคนเฅ‹เคคเคพ เคนเฅˆ

3. Security Risk

เคเค• thread เค•เฅ€ problem เคชเฅ‚เคฐเฅ‡ process เค•เฅ‹ affect เค•เคฐ เคธเค•เคคเฅ€ เคนเฅˆ

4. Deadlock Possibility

เค…เค—เคฐ threads proper coordination เคจ เค•เคฐเฅ‡เค‚, เคคเฅ‹ deadlock เคนเฅ‹ เคธเค•เคคเคพ เคนเฅˆ

Example (เคธเคฎเคเคจเฅ‡ เค•เฅ‡ เคฒเคฟเค)

เคฎเคพเคจ เคฒเฅ‹ เคเค• browser process เคนเฅˆ:

  • Thread 1 page load เค•เคฐ เคฐเคนเคพ เคนเฅˆ
  • Thread 2 video play เค•เคฐ เคฐเคนเคพ เคนเฅˆ
  • Thread 3 file download เค•เคฐ เคฐเคนเคพ เคนเฅˆ
  • Thread 4 user input handle เค•เคฐ เคฐเคนเคพ เคนเฅˆ

เคฏเคน เคธเคญเฅ€ threads เคเค• เคนเฅ€ process เค•เฅ‡ เค…เค‚เคฆเคฐ เค•เคพเคฎ เค•เคฐ เคฐเคนเฅ‡ เคนเฅˆเค‚เฅค
เค‡เคธเฅ€ เคตเคœเคน เคธเฅ‡ browser fast เค”เคฐ responsive เคฒเค—เคคเคพ เคนเฅˆเฅค

Real Life Analogy

เคเค• office เค•เฅ‹ process เคฎเคพเคจเฅ‹ เค”เคฐ office เค•เฅ‡ employees เค•เฅ‹ threadsเฅค

  • Office = Process
  • Employees = Threads

เคธเคญเฅ€ employees same office resources use เค•เคฐเคคเฅ‡ เคนเฅˆเค‚, เคฒเฅ‡เค•เคฟเคจ เคนเคฐ employee เค•เคพ เค•เคพเคฎ เค…เคฒเค— เคนเฅ‹เคคเคพ เคนเฅˆเฅค
เค‡เคธเฅ€ เคคเคฐเคน threads process เค•เฅ‡ resources share เค•เคฐเคคเฅ‡ เคนเฅเค เค…เคฒเค—-เค…เคฒเค— tasks เค•เคฐเคคเฅ‡ เคนเฅˆเค‚เฅค

Exam Point of View

Threads topic เคฎเฅ‡เค‚ เค…เค•เฅเคธเคฐ เคฏเฅ‡ points เคชเฅ‚เค›เฅ‡ เคœเคพเคคเฅ‡ เคนเฅˆเค‚:

  • Thread เค•เฅเคฏเคพ เคนเฅˆ
  • Process aur Thread เคฎเฅ‡เค‚ เค…เค‚เคคเคฐ
  • Multithreading เค•เฅเคฏเคพ เคนเฅˆ
  • User-Level aur Kernel-Level Threads
  • Threads เค•เฅ‡ advantages

Conclusion

Threads Operating System เค•เคพ เคฌเคนเฅเคค important concept เคนเฅˆเฅค
เคฏเคน เคเค• process เค•เฅ‡ เค…เค‚เคฆเคฐ multiple execution units provide เค•เคฐเคคเฅ‡ เคนเฅˆเค‚, เคœเคฟเคธเคธเฅ‡ system fast, efficient เค”เคฐ responsive เคฌเคจเคคเคพ เคนเฅˆเฅค

Modern applications เคฎเฅ‡เค‚ multithreading เค•เคพ use เคฌเคนเฅเคค common เคนเฅˆ, เค•เฅเคฏเฅ‹เค‚เค•เคฟ เค‡เคธเคธเฅ‡ เคเค• เคนเฅ€ application เค•เคˆ เค•เคพเคฎ เคเค• เคธเคพเคฅ handle เค•เคฐ เคธเค•เคคเฅ€ เคนเฅˆเฅค

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top