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

前端 未结 8 1535
轮回少年
轮回少年 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条回答
  •  Happy的楠姐
    2021-02-06 00:19

    Most of the solutions have a problem that data is kept public, thus one can access it without locking the lock.

    There is a way to fix that, but you can't use templates and thus have to resort to macros. It is much nicer to implement in C++11 and rather then repeating the whole discussion here, I link to my implementation on: https://github.com/sveljko/lockstrap

提交回复
热议问题