[Erlang 0077] Erlang note v

Source: Internet
Author: User

[1] The goal of Erlang is concurrency. The core mechanism supporting concurrency is the process "Making reliable distributed systems in the presence of sodware errors" [PDF]

 

[2] concurrency is a kind of ability to execute in non-sequential order. parallelism is a kind of "can be done at the same time" from the perspective of processing execution. There is also a kind of angle: concurrency occurs logically at the same time (simultaneous), while parallelism occurs physically at the same time.

 

[3] In fact, both process-oriented and object-oriented, various programming paradigms are abstract in the real world, but focus on different points.

 

[4] shared memory cocould reasonably be called The Goto of our time: It's the current mainstream technique for Process Communication; it has been so for a long, long time; and just like programming with Goto, there are numerous ways to shoot yourself in the foot.

 

[5] in Erlang, the message passing primitives are asynchronous, because it's easy to implement the synchronous form when necessary by making the cipher er always send an explicit reply that the sender can wait.

 

[6] copying data can be expensive for large structures and can cause higher memory usage if the sender also needs to keep their copy of the data. in practice, this means you must be aware of and manage the size and complexity of messages you're sending. but in normal, idiomatic Erlang programs, the majority of messages are small, and the overhead of copying is usually negligible. [7] a typical thread in a modern operating system reserves some megabytes of address space for its stack (which means a 32-bit machine can never have more than a few thousand simultaneous threads ), and it still crashes if it uses more stack space than expected. erlang processes, on the other hand, start with only a couple of hundred bytes of stack space each, and they grow or shrink automatically as required. [8] OTP framework provides just about everything you need: both a methodology for structuring applications using supervision, and stable, battle-hardened libraries to build them on. [9] at the lowest levels of the system, Erlang does all I/O in an event-based way, which lets a program handle each chunk of data as it enters or leaves the system in a nonblocking manner. this vulnerability CES the need to set up and tear down connections, and it removes the need for OS-based locking and context switching. [10] constants in the code will be compiled and optimized in the pool during hipe. For example, the following code will not create constant strings repeatedly.

 

Para (text)->

["<P class = \" normal \ ">", text, "</P>"].

Http://prog21.dadgum.com/10.html

 

[11] hipe_bifs: bitarray provides an introduction to the role of setbit getbit in redis commands @ Yufeng

Eshell V5.9  (abort with ^G)1> hipe_bifs:bitarray(10,false).<<0,0>>2> hipe_bifs:bitarray_update(v(1), 3, true).<<8,0>>3> hipe_bifs:bitarray_update(v(2), 7, true).<<136,0>>4> hipe_bifs:bitarray_update(v(3), 1, true).<<138,0>>5> hipe_bifs:bitarray_sub(v(4), 1).true6> hipe_bifs:bitarray_sub(v(4), 2).false7> hipe_bifs:bitarray_sub(v(4), 3).true8> hipe_bifs:bitarray_sub(v(4), 4).false9> hipe_bifs:bitarray_sub(v(4), 7).true10> 

 

 

[12] The external term format is mainly used in the distribution mechanic of Erlang.

Http://www.erlang.org/doc/apps/erts/erl_ext_dist.html look at the following test code

 

Eshell V5.9  (abort with ^G)(node_b@192.168.10.160)1> net_adm:ping('node_a@192.168.10.160').pong(node_b@192.168.10.160)2> {a_shell,'node_a@192.168.10.160'}!hello_world.hello_world(node_b@192.168.10.160)3> {a_shell,'node_a@192.168.10.160'}!self().     <0.38.0>(node_b@192.168.10.160)4> 

 

Eshell V5.9  (abort with ^G)(node_a@192.168.10.160)1> register(a_shell,self()).     true(node_a@192.168.10.160)2> flush().Shell got hello_worldok(node_a@192.168.10.160)3> flush().Shell got <5911.38.0>ok(node_a@192.168.10.160)4> node(pid(5911,38,0)).'node_b@192.168.10.160'(node_a@192.168.10.160)5> 

 

 

 

[13] Why is the shell process restarted and the original variable is still

You can take a look at erl5.9.1 \ Lib \ stdlib-1.18.1 \ SRC \ shell. erl code. The processing logic of the shell process after an exception includes the shell_rep (EV, bs0, RT, ds0) method for variable binding.

 

Eshell V5.9.1  (abort with ^G)1> self().<0.30.0>2> B=23.233> 1/0.** exception error: bad argument in an arithmetic expression     in operator  '/'/2        called as 1 / 04> self().<0.34.0>5> B.236> b().B = 23ok

 

Code snippet:

 

View code

shell_rep(Ev, Bs0, RT, Ds0) ->    receive     {shell_rep,Ev,{value,V,Bs,Ds}} ->         {V,Ev,Bs,Ds};        {shell_rep,Ev,{command_error,{Line,M,Error}}} ->            fwrite_severity(benign, <<"~w: ~s">>,                            [Line, M:format_error(Error)]),            {{'EXIT',Error},Ev,Bs0,Ds0};     {shell_req,Ev,get_cmd} ->         Ev ! {shell_rep,self(),get()},         shell_rep(Ev, Bs0, RT, Ds0);     {shell_req,Ev,exit} ->         Ev ! {shell_rep,self(),exit},         exit(normal);     {shell_req,Ev,{update_dict,Ds}} ->     % Update dictionary         Ev ! {shell_rep,self(),ok},         shell_rep(Ev, Bs0, RT, Ds);        {ev_exit,{Ev,Class,Reason0}} ->         % It has exited unnaturally            receive {'EXIT',Ev,normal} -> ok end,         report_exception(Class, Reason0, RT),            Reason = nocatch(Class, Reason0),         {{'EXIT',Reason},start_eval(Bs0, RT, Ds0), Bs0, Ds0};        {ev_caught,{Ev,Class,Reason0}} ->       % catch_exception is in effect         report_exception(Class, benign, Reason0, RT),            Reason = nocatch(Class, Reason0),            {{'EXIT',Reason},Ev,Bs0,Ds0};     {'EXIT',_Id,interrupt} ->          % Someone interrupted us         exit(Ev, kill),         shell_rep(Ev, Bs0, RT, Ds0);        {'EXIT',Ev,{Reason,Stacktrace}} ->            report_exception(exit, {Reason,Stacktrace}, RT),         {{'EXIT',Reason},start_eval(Bs0, RT, Ds0), Bs0, Ds0};        {'EXIT',Ev,Reason} ->            report_exception(exit, {Reason,[]}, RT),         {{'EXIT',Reason},start_eval(Bs0, RT, Ds0), Bs0, Ds0};     {'EXIT',_Id,R} ->         exit(Ev, R),         exit(R);     _Other ->                    % Ignore everything else         shell_rep(Ev, Bs0, RT, Ds0)    end.

 

[14] % The module has been loaded and has a specified method for export. Note that the last parameter is the number of operations represented by Arity.

Erlang: function_exported (module, function, Arity)-> bool ()
Types:
Module = function = atom ()
Arity = int ()
Returns true if the module is loaded and contains an exported function/Arity; otherwise
False.
Returns false for any BIF (functions implemented in C rather than in Erlang ).

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.