C # and JAVA is a product of the two, both design idea and syntax format is very similar to that of phase slay hate others along the way with a group of fans, ideas are passing on the object-oriented c + +, but say is closer to the blood relationship or c #, retained more of the shadow of the c + + lets a person much a few minutes the familiar smell, VS on IDE is also a much better user experience than MyEclipse. No idea is used to compare the obvious bias VS, well you’re right.

C# and C++ both provide a good and complete synchronization mechanism between threads. C# retains more of the C++ brand, while JAVA is more streamlined and easier for developers. In the past, in the process oriented programming, the operation of lock is basically based on the statement, the scope of lock from the start of lock to unlock termination, the process of code writing all kinds of careful lock interval logic processing, an exception may lead to eternal deadlock. C# and JAVA encapsulate more lock-oriented operations, greatly simplifying steps by giving object instances a modifier. Of course, you can also lock statement blocks, eliminating explicit tedious operations.


C# JAVA C++
To obtain

Monitor.Enter(object);

Monitor.TryEnter(object);



dormancy Monitor.Wait(object); final void wait();

pthread_cond_wait(_cond, _mutex);

pthread_cond_timewait(_cond, _mutex, _abstime);

Wake up the

Monitor.Pulse(object);

Monitor.PulseAll(object);

final void notify();

final void notifyAll();

pthread_cond_signal(_cond);

pthread_cond_broadcast (_cond);

The release of Monitor.Exit(object);

The table above shows the c # and JAVA language synchronization method based on the monitor function, c # more than JAVA to monitor access and the release of the operation, both provide dormancy wait time, wake up operations provides two methods of unicast and multicast, in clearly awakened object and to predict its execution under the premise of methods and results suggest unicast way to wake up, Otherwise, the alarm context switch caused by multicast wake up and then put to sleep one by one will cause relatively large system overhead. It’s important to note that following Oracle’s recommendation to put wait() into a loop can help avoid spurious wakeup, although Oralce emphasizes that it’s extremely rare, which means: ‘I’m telling you, it’s your fault. Don’t call me.’ The table uses C++ as a background to better compare the application of this mechanism, which is not simple brute lock unlocking, but conditional and scale exclusive operations with minimal overhead.

public void CSharpFunc(int v) { Monitor.Enter(this); if (flag) { try { Monitor.Wait(this); } catch(SynchironizationLockException e) { Console.WriteLine(e); } } Console.Write("Value {0}", v); flag = true; Monitor.Pulse(this); Monitor.Exit(this); } synchronized void JavaFunc(int v) { while (! flag) try { wait(); } catch(InterruptedException e) { System.out.println("InterruptedException caught"); } System.out.println("Valuse: " + v); flag = false; notify(); }Copy the code


Shared a few days ago to go out to experience a 7 motorcycles, thought can do whatever you want without pile cycling, result the deposit and prepaid phone, sweep code lock to specify the destination, because there is no parking lot around destination, have to ride to the station and then transfer to, this call what matter ah, zhang lying down on the amount of residual charge, carry out and I don’t know what time next time consumption, It feels like a dupe. Pile-sharing vehicles are designed against humanity. Change it.