← 返回 Skills 市场
wu-uk

erlang-concurrency

作者 wu-uk · GitHub ↗ · v0.1.0 · MIT-0
cross-platform ✓ 安全检测通过
77
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install fix-erlang-ssh-cve-erlang-concurrency
功能描述
Use when erlang's concurrency model including lightweight processes, message passing, process links and monitors, error handling patterns, selective receive,...
使用说明 (SKILL.md)

Erlang Concurrency

Introduction

Erlang's concurrency model based on lightweight processes and message passing enables building massively scalable systems. Processes are isolated with no shared memory, communicating asynchronously through messages. This model eliminates concurrency bugs common in shared-memory systems.

The BEAM VM efficiently schedules millions of processes, each with its own heap and mailbox. Process creation is fast and cheap, enabling "process per entity" designs. Links and monitors provide failure detection, while selective receive enables flexible message handling patterns.

This skill covers process creation and spawning, message passing patterns, process links and monitors, selective receive, error propagation, concurrent design patterns, and building scalable concurrent systems.

Process Creation and Spawning

Create lightweight processes for concurrent task execution.

%% Basic process spawning
simple_spawn() ->
    Pid = spawn(fun() ->
        io:format("Hello from process ~p~n", [self()])
    end),
    Pid.

%% Spawn with arguments
spawn_with_args(Message) ->
    spawn(fun() ->
        io:format("Message: ~p~n", [Message])
    end).

%% Spawn and register
spawn_registered() ->
    Pid = spawn(fun() -> loop() end),
    register(my_process, Pid),
    Pid.

loop() ->
    receive
        stop -> ok;
        Msg ->
            io:format("Received: ~p~n", [Msg]),
            loop()
    end.

%% Spawn link (linked processes)
spawn_linked() ->
    spawn_link(fun() ->
        timer:sleep(1000),
        io:format("Linked process done~n")
    end).

%% Spawn monitor
spawn_monitored() ->
    {Pid, Ref} = spawn_monitor(fun() ->
        timer:sleep(500),
        exit(normal)
    end),
    {Pid, Ref}.

%% Process pools
create_pool(N) ->
    [spawn(fun() -> worker_loop() end) || _ \x3C- lists:seq(1, N)].

worker_loop() ->
    receive
        {work, Data, From} ->
            Result = process_data(Data),
            From ! {result, Result},
            worker_loop();
        stop ->
            ok
    end.

process_data(Data) -> Data * 2.

%% Parallel map
pmap(F, List) ->
    Parent = self(),
    Pids = [spawn(fun() ->
        Parent ! {self(), F(X)}
    end) || X \x3C- List],
    [receive {Pid, Result} -> Result end || Pid \x3C- Pids].


%% Fork-join pattern
fork_join(Tasks) ->
    Self = self(),
    Pids = [spawn(fun() ->
        Result = Task(),
        Self ! {self(), Result}
    end) || Task \x3C- Tasks],
    [receive {Pid, Result} -> Result end || Pid \x3C- Pids].

Lightweight processes enable massive concurrency with minimal overhead.

Message Passing Patterns

Processes communicate through asynchronous message passing without shared memory.

%% Send and receive
send_message() ->
    Pid = spawn(fun() ->
        receive
            {From, Msg} ->
                io:format("Received: ~p~n", [Msg]),
                From ! {reply, "Acknowledged"}
        end
    end),
    Pid ! {self(), "Hello"},
    receive
        {reply, Response} ->
            io:format("Response: ~p~n", [Response])
    after 5000 ->
        io:format("Timeout~n")
    end.

%% Request-response pattern
request(Pid, Request) ->
    Ref = make_ref(),
    Pid ! {self(), Ref, Request},
    receive
        {Ref, Response} -> {ok, Response}
    after 5000 ->
        {error, timeout}
    end.

server_loop() ->
    receive
        {From, Ref, {add, A, B}} ->
            From ! {Ref, A + B},
            server_loop();
        {From, Ref, {multiply, A, B}} ->
            From ! {Ref, A * B},
            server_loop();
        stop -> ok
    end.

%% Publish-subscribe
start_pubsub() ->
    spawn(fun() -> pubsub_loop([]) end).

pubsub_loop(Subscribers) ->
    receive
        {subscribe, Pid} ->
            pubsub_loop([Pid | Subscribers]);
        {unsubscribe, Pid} ->
            pubsub_loop(lists:delete(Pid, Subscribers));
        {publish, Message} ->
            [Pid ! {message, Message} || Pid \x3C- Subscribers],
            pubsub_loop(Subscribers)
    end.

%% Pipeline pattern
pipeline(Data, Functions) ->
    lists:foldl(fun(F, Acc) -> F(Acc) end, Data, Functions).

concurrent_pipeline(Data, Stages) ->
    Self = self(),
    lists:foldl(fun(Stage, AccData) ->
        Pid = spawn(fun() ->
            Result = Stage(AccData),
            Self ! {result, Result}
        end),
        receive {result, R} -> R end
    end, Data, Stages).

Message passing enables safe concurrent communication without locks.

Links and Monitors

Links bidirectionally connect processes while monitors provide one-way observation.

%% Process linking
link_example() ->
    process_flag(trap_exit, true),
    Pid = spawn_link(fun() ->
        timer:sleep(1000),
        exit(normal)
    end),
    receive
        {'EXIT', Pid, Reason} ->
            io:format("Process exited: ~p~n", [Reason])
    end.

%% Monitoring
monitor_example() ->
    Pid = spawn(fun() ->
        timer:sleep(500),
        exit(normal)
    end),
    Ref = monitor(process, Pid),
    receive
        {'DOWN', Ref, process, Pid, Reason} ->
            io:format("Process down: ~p~n", [Reason])
    end.

%% Supervisor pattern
supervisor() ->
    process_flag(trap_exit, true),
    Worker = spawn_link(fun() -> worker() end),
    supervisor_loop(Worker).

supervisor_loop(Worker) ->
    receive
        {'EXIT', Worker, _Reason} ->
            NewWorker = spawn_link(fun() -> worker() end),
            supervisor_loop(NewWorker)
    end.

worker() ->
    receive
        crash -> exit(crashed);
        work -> worker()
    end.

Links and monitors enable building fault-tolerant systems with automatic failure detection.

Best Practices

  1. Create processes liberally as they are lightweight and cheap to spawn

  2. Use message passing exclusively for inter-process communication without shared state

  3. Implement proper timeouts on receives to prevent indefinite blocking

  4. Use monitors for one-way observation when bidirectional linking unnecessary

  5. Keep process state minimal to reduce memory usage per process

  6. Use registered names sparingly as global names limit scalability

  7. Implement proper error handling with links and monitors for fault tolerance

  8. Use selective receive to handle specific messages while leaving others queued

  9. Avoid message accumulation by handling all message patterns in receive clauses

  10. Profile concurrent systems to identify bottlenecks and optimize hot paths

Common Pitfalls

  1. Creating too few processes underutilizes Erlang's concurrency model

  2. Not using timeouts in receive causes indefinite blocking on failure

  3. Accumulating messages in mailboxes causes memory leaks and performance degradation

  4. Using shared ETS tables as mutex replacement defeats isolation benefits

  5. Not handling all message types causes mailbox overflow with unmatched messages

  6. Forgetting to trap exits in supervisors prevents proper error handling

  7. Creating circular links causes cascading failures without proper supervision

  8. Using processes for fine-grained parallelism adds overhead without benefits

  9. Not monitoring spawned processes loses track of failures

  10. Overusing registered names creates single points of failure and contention

When to Use This Skill

Apply processes for concurrent tasks requiring isolation and independent state.

Use message passing for all inter-process communication in distributed systems.

Leverage links and monitors to build fault-tolerant supervision hierarchies.

Create process pools for concurrent request handling and parallel computation.

Use selective receive for complex message handling protocols.

Resources

安全使用建议
This skill is a documentation/tutorial-only resource and is internally consistent with its stated purpose. If you plan to let agents invoke skills autonomously, note that this skill has no provenance (no homepage/source repository) and no owner details beyond an ID—if that matters to you, verify the publisher or test the skill in a restricted environment first. Also, the SKILL.md contains runnable Erlang code examples: review and test examples in a controlled/dev environment before copying them into production systems. If you want extra caution, disable autonomous invocation for this skill or ask the publisher for source/repo information.
功能分析
Type: OpenClaw Skill Name: fix-erlang-ssh-cve-erlang-concurrency Version: 0.1.0 The skill bundle contains standard educational material and code examples for Erlang concurrency patterns (processes, message passing, links, and monitors). While the slug in _meta.json ('fix-erlang-ssh-cve-erlang-concurrency') is slightly inconsistent with the purely educational content in SKILL.md, the code itself is safe, lacks any high-risk capabilities such as shell execution or network access, and contains no evidence of malicious intent or prompt injection.
能力评估
Purpose & Capability
The name/description (Erlang concurrency) matches the SKILL.md content: explanatory text and example Erlang code demonstrating processes, message passing, links/monitors, supervisors, and patterns. There are no unrelated requirements (no credentials, binaries, or installs).
Instruction Scope
SKILL.md contains code samples and conceptual guidance only; it does not instruct the agent to read files, access environment variables, call external endpoints, or run shell commands. The instructions stay within the stated scope of teaching Erlang concurrency patterns.
Install Mechanism
No install specification is present (instruction-only). Nothing will be downloaded or written to disk by an installer—this is the lowest-risk model and is proportional to the skill's purpose.
Credentials
The skill declares no required environment variables, credentials, or config paths, which is appropriate for a documentation/teaching skill that provides code examples.
Persistence & Privilege
always is false and the skill does not request persistent or elevated platform privileges. Model invocation is allowed (the default) but combined with the benign scope and lack of credentials this is not concerning.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install fix-erlang-ssh-cve-erlang-concurrency
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /fix-erlang-ssh-cve-erlang-concurrency 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v0.1.0
Bulk publish from all-task-skills-dedup
元数据
Slug fix-erlang-ssh-cve-erlang-concurrency
版本 0.1.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

erlang-concurrency 是什么?

Use when erlang's concurrency model including lightweight processes, message passing, process links and monitors, error handling patterns, selective receive,... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 77 次。

如何安装 erlang-concurrency?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install fix-erlang-ssh-cve-erlang-concurrency」即可一键安装,无需额外配置。

erlang-concurrency 是免费的吗?

是的,erlang-concurrency 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

erlang-concurrency 支持哪些平台?

erlang-concurrency 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 erlang-concurrency?

由 wu-uk(@wu-uk)开发并维护,当前版本 v0.1.0。

💬 留言讨论