【发布时间】:2011-12-28 08:46:30
【问题描述】:
我正在尝试用 pthread 做一些事情并同步它们:
我怎么能只对一组线程使用互斥锁?
假设我有 t0,t1, t2, .. t20。 pthreads 同时运行,我想为偶数线程锁一个锁,为奇数线程锁一个锁......或者前十个锁一个锁,其余锁另一个,或者一个锁定每个。我的意思是,根据数据对 pthread 进行分组(此函数中的第四个参数:
int pthread_create(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine)(void *), void *arg);
并为一组 pthread 共享互斥锁。
我正在从事一种银行项目,我想锁定所有试图访问同一个帐号的 preads。 (作为关键部分 CRUD 操作)
是否有意义 ?还是有更好的方法来做到这一点?
提前感谢您的帮助和时间;)
J.
【问题讨论】:
-
我刚想到一个类似的问题,不确定它是否与银行账户有关,但您可能想检查一下:stackoverflow.com/questions/18493241/…
标签: c unix synchronization pthreads mutex