太难了

  • 主题发起人 主题发起人 wind
  • 开始时间 开始时间
最初由 wind 发布


synchronized只是阻止multi thread同时进入某一部分code,并不意味着可以将相关数据存在该single instance的private member里。

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?".
 
最初由 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.

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?
 
最初由 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?".

你的问题和那位女同事的不一样。你是真需要'global varibles',也就是呢需要varibles in different theads overwrite each other。我想只能用synchronized来控制对'global varibles'的存取。

那位女同事的问题是,她试图用singleton为不同threads存放不同的values.
 
最初由 wind 发布


你的问题和那位女同事的不一样。你是真需要'global varibles',也就是呢需要varibles in different theads overwrite each other。我想只能用synchronized来控制对'global varibles'的存取。

那位女同事的问题是,她试图用singleton为不同threads存放不同的values.

:eek: :eek: :eek:

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?
 
最初由 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?
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.
 
都说老外虚伪, 他们害你的时候都说的是好听的话. 这事如果换个角度, 是你老板问其他同事, 他们会怎么说你, 八成说你是个 nice guy 什么的, 或者说code 有点特色之类的废话, 言外之意是你做的东西有错或没用. 但是他们不直说.

要是你肯定老板准备请你同事大姐走路的话, 你也救不了她, 你就也只好虚伪一把了, 用点策略的话表达出你的实际意思, 说直了将来传给大姐多难堪, 不实说, 那老板问你干什么. 是太难了. 你要是对工作的责任感第一, 对同事的友谊第二的话, 就用老外的虚伪去对付老外吧.
 
最初由 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.

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 :rolleyes:
 
最初由 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 :rolleyes:
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.
 
最初由 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.
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.

Now I am a happy Masters student, wondering if I should completely get out of IT or stay as a student for ever.
 
最初由 wind 发布

那位女同事的问题是,她试图用singleton为不同threads存放不同的values.

这当然不行!
小声问一声:她的Design/code reviewer(s), 或者peer reviewer 应该发现这个问题吧?
如果没有这些reviewers, 你老板要承担一部份责任吧?
 
最初由 wei 发布


:eek: :eek: :eek:

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?

My understanding is that the singleton was needed in her code. However, some variables for different threads should be moved out from that singleton, maybe kept in different objects created by each thread. Another approach is to use a Hash Table keyed by thread id. Anyway, this is just a Nortel old uncle's 2 cents. :D
 
如果仅是那个multithreaded之类的问题也没什么,也许她忘掉写static,或是犯了一个什么低级错误(我想所有程序员有时都这样),我们公司水平不咋样的老外用锹产。这就看你怎么说了。
 
Re: Re: 太难了

最初由 phonecard 发布


该如何办如何办吧,你也是为老板打工啊,我想你能做的也许就是告诉那老姐姐一声, 看她自己有没有办法了.

Agree, be honest and professional.
 
同意WIN98的话,你什么也不说。说也是不疼不痒的话,老板想干什么他早就想好了,根本也不用你帮他做决定。这公司是你的行了,对自己公司本着负责的精神,给人家打工别太认真。
 
My 2 cents

Everyone know that you have a good heart but also have a tricky boss to test you as well. Here is my 2 cents.

1st cent: Honestly tell your boss the problems in your co-worker's code. You could list some major and minor ones together. Maybe your boss only understand minor issues.
2nd cent: For youself, all her code bugs are very easy to fix. They are just a piece of cake for you. This is the most important. It not only demonstrate your ability and skill but also do protect your co-worker.
 
后退
顶部