Thread Programming Performance Tips

  • Read is faster than write, when memory content in symmetric mutil-processing(SMP)
  • Minimized the cost in locking and synrhronization

    • Code based locks
    • Data based locks

  • Not overhead in lock / unlock
  • Trial and error process
  • Blocking vs spinning

    • Depends on the frequency of request
    • Average time the lock
    • Spinlocks only on SMP machines
    • Own locking primitives better than operating system if waiting time for locks is less than the context switching time of a thread

  • Locking

    • Not hold locks for long duration
    • Not have too fine grained locks
    • Not perform blocking operation while holding locks
    • Avoid deadlocks
Reference
  • CS4282 Internet & Distribution System Program of City University