Skip to content

Threading

IT Notes → C# @ December 22, 2020

  • System.Threading.
  • Thread t = new Thread(fn);  //Here in actuality we pass delegate
  • A threads IsAlive property returns true, until the point where the thread ends.
  • A separate copy of the local variable is created on each thread’s memory stack.
  • Threads share data if they have a common reference to the same object instance.
  • Static fields offer another way to share data between threads.
  • Thread safety where output is deterministic.
  • The remedy is to obtain an exclusive lock while reading and writing to the common field.
  • When two threads simultaneously contend a lock (in this case, locker), one thread waits, or blocks, until the lock becomes available.
  • So critical section is entered only one at a time.
  • While waiting on a Sleep (the current thread waits for specific time) or Join (other threads wait), a thread is blocked and so does not consume CPU resources.
  • Join returns true if the thread ended or false if it timed out.
  • Sleep(0) relinquishes the threads current time slice immediately to CPU and Yield function to processes on same processor.
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x