美文网首页
14-513: CSAPP 026: Synchronizati

14-513: CSAPP 026: Synchronizati

作者: Ysgc | 来源:发表于2020-01-06 13:52 被阅读0次

semaphore counts resources

reads usually dominate writes, eg. database
rarely, writes are way more than reads, eg. log server

so one policy is to let the writer to wait until there's no reader, and reader has high priority.

two mutexes!

'mutex' ~> for reader counting
'w' ~> for readers dominating writers

  • Question:



    why these two lines should be in the critical section?

  • Answer:
    the shared var "readcnt" should be protected

how does the first reader excludes writers?

symmetric!

in a stream of readers, when a writer comes in, the writer will require a 'r', to prevent further readers from running.

and 'wmutex' is a mutex to protect the 'writecnt'

circular wait

deadlock -> threads acquire resource not in the same sequence

what if 2 threads using rand and one of them called srand

remove the static next

each srand malloc a new next

so the programmer has to maintain the seed, and need to free the variable

没看懂???

相关文章

网友评论

      本文标题:14-513: CSAPP 026: Synchronizati

      本文链接:https://www.haomeiwen.com/subject/jhkgnctx.html