What's the proper way to associate a mutex with its data?

前端 未结 8 1407
轮回少年
轮回少年 2021-02-05 23:44

In the classic problem of transferring money from one bank account to another, the accepted solution (I believe) is to associate a mutex with each bank account, then lock both b

8条回答
  •  再見小時候
    2021-02-06 00:28

    Your problem is to associate the locking with the data. In my eyes, stuffing the mutex into the object is fine. You could go even further, making the objects essentially into monitors: Lock to enter a function member, unlock when leaving.

提交回复
热议问题