dalby
@dalby
Best posts made by dalby
Latest posts made by dalby
-
RE: Synchronized everything!
Well.. the code you provided for us to see didn't cause any locking issues or did it? So basically you were bashing him over... nothing? And I'm not being argumentative, I'm just saying your example wasn't causing anything you implied. Sorry for being right.
-
RE: Synchronized everything!
And it is not about terminology... a deadlock is not a starvation. And if you know the basics of computer science you agree.
-
RE: Synchronized everything!
So the whole point was an utterly stupid commit statement? Wow! You really are the first to post a stupid version control commit statement.
-
RE: Synchronized everything!
And to mr enterprise architect... you seem to be an example of your kind. You provided an example code (in java AND c) which wasn't related to question at all. And after that you are trying to correct me... please don't. I'm probably better at your job than you are now. If you don't get it, please read again.
-
RE: Synchronized everything!
If you didn't get it... it wasn't a deadlock. Your example wasn't about the deadlock at all. An example which deadlocks with given circumstances would suffice... but I think it is not possible.
-
RE: Synchronized everything!
Well... it wasn't a deadlock. It may appear to be a deadlock, but if you carefully check out your example you realize it is NOT a deadlock. I'm sorry but you really should provide an example and you have failed. This is not an easy task to do. Concurrent programming seems to be easy to fail ... or is it?
-
RE: Synchronized everything!
@Enterprise Architect said:
Confirmed:
public class Demo {
private int doucheRunCount = 0;public static void main(String args[ ]) { new Demo().run(); } public void run() { Thread douche = new Thread() { public void run() { while(true) { synchronized(Demo.this) { try { sleep(5000); // What a douche } catch (InterruptedException e) { // Who cares?! } ++doucheRunCount; } } } }; Thread reader = new Thread() { public void run() { while(true) { synchronized(Demo.this) { System.out.println( String.format("Douche has run %d times", doucheRunCount)); } } } }; reader.start(); douche.start(); }
}
This is NOT per my request at all. Try again using those synchronized methods, I still think it can't deadlock because the example was oversimplified.
Another thing is that your example does not deadlock at all if you change that 5000 ms to 1 ms but it runs perfectly... which implies that your example does NOT deadlock. 5 seconds grab to that lock is just plain stupid but it wasn't asked here.
TRWTF is the C is shorter than the Java…
Why? And why you are using String.format() instead of System.out.format()? Btw, Java has for (;;) too.
-
RE: Synchronized everything!
@Heron said:
I'm pretty sure I already explained exactly what caused the deadlock :P
Did you explain it exactly?-) I don't get how this causes deadlocks:
Object member; // this is set somewhere public synchronized Object getMember() { return member; } public synchronized Object getFoo() { // code to generate foo, NOT RELATED TO member nor to getMember() return new Object(); }
Could you provide code example generating that deadlock?