p******g 发帖数: 347 | 1 Check out the CountdownLatch in Java. it's just what you needed, and it's
fairly easy to implement it with pthread semaphore or what ever
synchronization stuff. CyclicBarrier works for you, too.
同步
tL2a |
|
d*********8 发帖数: 2192 | 2 这要取决于内核怎么作业调度了。通常可以调用Thread.yeild()之类的主动让出来。各
个语言/OS有自己的实现。有时候就是sleep(0) |
|
d*********8 发帖数: 2192 | 3 而且SLEEP(0)也不一定好用。记得某个WINDOWS版本下有BUG,只能用Sleep(1) |
|
v*****r 发帖数: 1119 | 4 Sounds like RR is actually not used. You probably have to run your program
as root for "RR调度方式" to be effective, otherwise the RR request could be
just ignored.
Kick off your program, and run this command to verify:
ps -p -m -o pid,cls,rtprio,command |
|
z*******6 发帖数: 133 | 5 试试用 automake,cmake等, 先把 project/solution 搞出来。
然后参考刚才上上贴对header file 的处理。一步步来,有些头文件对应的列表,可以
在网络上搜搜,比如 unistd.h, sys/*.h, dirent.h; 第三方的库也要准备好。
几个问题如果系统中没有用的话,还是可以很快完成的。
1. GUI,如果有motif xwin 等的界面,试试用 QT
2. 如果有opengl, 需要用 glew, regular expression 也需要单独的库
3. 如果有遇到share memory/semaphore 的部分,需要重新做
4. 如果有文件io 的低级操作的部分,要重来
5. 如果有遇到 signal 的处理的部分,估计要重来。
6. 。。。 |
|
r****t 发帖数: 10904 | 6 以及 mv 文件的时候,内核如何防止 race condition? inode semaphore 具体来讲是
怎么设置的? |
|
G*****h 发帖数: 33134 | 7 就算要搞,也是某种 semaphore
user mode thread 死等 it 被触发 |
|
|
|
m********2 发帖数: 89 | 10 spinlock 不 reschedule.
mutex 会 reschedule.
spinlock 跟 mutex 比更合适。 |
|
b*******s 发帖数: 5216 | 11 补充一点,spinlock是busy waiting,在并发冲突少的时候效率高
如果并发冲突频繁,还是要用锁 |
|
b********n 发帖数: 609 | 12 找到的相关要求,有兴趣可以开始玩了。
Strong real-time development skills including UNIX IPC mechanisms (sockets,
shared memory, semaphores, etc.)
UNIX and/or POSIX multithreading development
Must be capable of developing and maintaining event-driven
server applications receiving high-volume data flow from scratch.
其实就三样,networking,multithreading,event-driven。 |
|
t****t 发帖数: 6806 | 13 because a kernel sem will not yield control to another user-mode thread in
case a waiting has to happen.
but |
|
bz 发帖数: 1770 | 14 you can, if you can give the user thread the access to the kernl sem. need
to be cautious though.
but |
|
p****s 发帖数: 32405 | 15 并行的, 这个用semaphore或mutex tasking的算法不行么? |
|
o******r 发帖数: 259 | 16 我指的就是用semaphore/mutex之类的来同步,
好象题目更偏重于OOP design
看你用什么object
往简单了说,一个booking, 一个table,一个confirmation
或加一个client GUI |
|
t*i 发帖数: 72 | 17 请问网上有没有比较全面介绍c++设计semaphores, multex 的资料, 推荐一下吧。 |
|
p***o 发帖数: 1252 | 18 Nice problem. I need as many semaphores as consumers and one lock.
Is there any better solution?
To prove the correctness is also interesting.
each
resource it
at
requires |
|
|
|
j**********p 发帖数: 22 | 21 This depends on specific implementations. |
|
|
|
l*****g 发帖数: 547 | 24 If you are using *NIX systems, POSIX IPC can give you sufficient supports:
Solution 1: message queue. but you will need thread support if two processes
running on different cycle times.
solution 2: semaphore + shares memory, but you need to make sure there is
no deadlock.
I am not sure how to do it on windows. |
|
|
D*******a 发帖数: 3688 | 26 thread,mutex,semaphore本来是OS的东西,所以不同操作系统下面用法不同
不过现在好像可以用boost::thread库 |
|
b***y 发帖数: 2799 | 27 就是啊,死等就行啊,另一个一释放,它就拿到了。这又不存在semaphore的问题。 |
|
g*****g 发帖数: 34805 | 28 mutex就是只有一个坑位,semaphore就是可以有多个坑位。
都是坑满了就得外面排队。 |
|
|
D*******a 发帖数: 3688 | 30 you can use binary semaphore as a mutex but not the other way around |
|
d****n 发帖数: 130 | 31 他们的功能是互相不重叠的吗? 还是实现相同目的的不同形式而已? |
|
m****t 发帖数: 37 | 32 mutex和lock我感觉是一样的,但是好像又感觉有区别
哪位给我说说吧 |
|
k***r 发帖数: 4260 | 33 mutex is a lock. Not the other way around. |
|
g*****g 发帖数: 34805 | 34 mutex as it's named, is mutually exclusive, a binary semophore |
|
m****t 发帖数: 37 | 35 so, mutex & lock are different? |
|
g*****g 发帖数: 34805 | 36 It's totally different concepts. Lock is a mechanism with
which client (read or write) can obtain the access.
Think of a single washroom, that's a lock. |
|
|
|
T*****9 发帖数: 2484 | 39 try to use the -lphread option when you compiler with gcc |
|
r*********r 发帖数: 3195 | 40 不奇怪. 可能两种都支持. Sys V 的强大, 但难用.
Posix 语义更清楚. 经常是 posix 的用 sys v 来实现, 本身只是一个wrapper.
但是 posix 又分两种, 有名的是 sem_open, 无名是 sem_init.
有可能系统只支持 sem_open, 因为 sem_init 只能用于线程, 不能用作 ipc. |
|
r*********r 发帖数: 3195 | 41 用 IPC_PRIVATE 就不能 share. |
|
n**d 发帖数: 9764 | 42 Besides Ftok(), is there any other way? |
|
r*********r 发帖数: 3195 | 43 如果你已经通过其它方法拿到了 key (比如 ipcs), 就不需要 ftok. |
|
i**p 发帖数: 902 | 44 Is there any command like ipcs for system V to show the un-destroied unnamed semaphore? |
|
r*********r 发帖数: 3195 | 45 unnamed semaphore 应该不涉及系统资源. destroy 就是把里面的 mutex, condition
variable, count 清零, 禁止再对其用p/v操作.
这种有可能涉及资源的, 用 c++ RAII 最安全, dtor 自动释放 whatever needed to
be released. |
|
|
z****e 发帖数: 2024 | 47 学过操作系统,but wang guang guang le. and i didn't hao hao xue, when in
college.
多线程编程, know some but not in depth. again, i didn't hao hao xue, when in
college:(.
i always chao zuo ye :). |
|
|
|
|