Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In it's original application space the primary apeal of Erlang (as well as Ericsson's custom CPUs in their exchanges) was that user's interaction with the system (eg. one phone call) can be implemented by one thread/process running normal sequential synchronous code as opposed to as state in some complex asynchronous state machine (ie. what is done in node.js) that is orders of magnitude more complex to program and understand. Another solution to this problem involves inventing some monads-and-arrows-reinvented (async/await...) machinery that hides the state machine away.

Multi-threaded programs have to be concerned with low-level details like memory ordering and barriers only when they do synchronization without using OS-provided utilities or when they implement synchronization wrong. pthread_mutex_lock() is both memory and optimization barrier and that is probably all one has to know for vast majority of MT code.



> when they implement synchronization wrong.

Yes, but there are lots of ways to implement synchronization wrong because you don't understand memory barriers.

For instance, Doug Lea's article linked above includes this very simple Java code, which breaks because it wasn't aware of memory barriers:

  // Broken multithreaded version
  // "Double-Checked Locking" idiom
  class Foo { 
    private Helper helper = null;
    public Helper getHelper() {
      if (helper == null) 
        synchronized(this) {
          if (helper == null) 
            helper = new Helper();
        }    
      return helper;
      }
    // other functions and members...
    }
[dfox: can't reply, guess we're nesting too deeply. Per the above, the simple rule has to be modified to "do not touch OR READ shared state outside of relevant critical section". Easy to make errors...]


There is simple rule for that: do not touch shared state outside of relevant critical section.

To some extent the cited problem is unique to Java, because the whole monitor concept just creates confusion about what synchronized really means (and also creates significant overhead by making literally everything usable as mutex). Pretty common misconception is that synchronized is akin to some kind of read-write lock (in which case the code above would work as expected).


AFAIK Ericsson never had custom CPUs.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: