曾经是
知名会员
- 注册
- 2002-01-27
- 消息
- 922
- 荣誉分数
- 0
- 声望点数
- 126
最初由 Edison 发布
In C/C++ with Unix, use shared memory to store semaphor/monitor. In java, I am not sure. But the synchronized methods should have the control and maintaince for each thread. If you want to study more, please see Steven's books.
最初由 wei 发布
I understand what synchronized means. My question is that "How the 'global varibles' can be implemented without using the data memebers in a static instance?".
最初由 wind 发布
你的问题和那位女同事的不一样。你是真需要'global varibles',也就是呢需要varibles in different theads overwrite each other。我想只能用synchronized来控制对'global varibles'的存取。
那位女同事的问题是,她试图用singleton为不同threads存放不同的values.
You have to write the code for synchronization by using shared memory to contain the semaphor which is the lock for your threads. The most hard work for shared memory is to maintain your shared momery. When your main program exit, the shared memory will stay in the system and the system will keep them until reboot. That is so-called memory leaking. The book is excellent, but it only provides the basic methods, for each different system, you must have system refernce and may discuss in the news groups for help. I real like the programming, but now it is hard to find this kind of jobs.最初由 wei 发布
Ha, that does the trick. How do you keep synchronization using C/C++? I always wonder about it.
You mean the big Unix books by Stevens?
最初由 wang2002 发布
You have to write the code for synchronization by using shared memory to contain the semaphor which is the lock for your threads. The most hard work for shared memory is to maintain your shared momery. When your main program exit, the shared memory will stay in the system and the system will keep them until reboot. That is so-called memory leaking. The book is excellent, but it only provides the basic methods, for each different system, you must have system refernce and may discuss in the news groups for help. I real like the programming, but now it is hard to find this kind of jobs.
Are you still working on this area or only worked previously? Steven was dead, and his books are real helpful. Keep on reading them again and again, and try the code in your system, you will learn more.最初由 wei 发布
Yes, I know memory leak is the biggest headche for C++/C programmers. I still have nightmares about how one single unnecessary "delete" statement crashs the whole system, and one missing "delete" causes the memory usage go up madly ...Sympathy for all programmers
Last time I worked with C++ was the beginning of year 2000. I was working with MFC to create some internal tools for a small company, which is not around any more. Never had a chance to write real time applications with C++, guess it must be fun, though.最初由 wang2002 发布
Are you still working on this area or only worked previously? Steven was dead, and his books are real helpful. Keep on reading them again and again, and try the code in your system, you will learn more.
最初由 wei 发布
Then it shouldn't be too hard to modify her code. Just take the "static" key word away (assuming you use Java/C++). Then fix the compiling errors caused by this modification. ...Am I being too optimistic here?