Process And thread

When two or more threads of a program share a collection, problems might occur. As an analogy,
consider a traffic intersection. If all cars were allowed to access the intersection at the same
time, collisions might occur. For this reason, traffic lights are provided to control access to
the intersection. Similarly, we can synchronize access to a collection to ensure that only one
thread manipulates the collection at a time. The synchronization wrapper methods of class
Collections return synchronized versions of collections that can be shared among threads
in a program.


Both processes and threads are independent sequences of execution. The typical difference is that threads (of the same process) run in a shared memory space, while processes run in separate memory spaces.
I'm not sure what "hardware" vs "software" threads might be referring to. Threads are an operating environment feature

Thread:

  • Provide ability to do multiple things at once within the same Application
  • Share address space
  • Can share variable directly
  • Finer granularity of concurrency
  • Light weight
  • Easy to create and destroy
  • May require more complex synchronization logic because of shared address space.
Process:
  • Provide ability to run multiple program at once
  • Separate address for every application
  • Cooperate using  steams.
  • Synchronization is easy as there is no shared address space.

0 comments:

Post a Comment

My Instagram