Skip to content

Instantly share code, notes, and snippets.

@kvakvs
Created September 9, 2020 12:16
Show Gist options
  • Save kvakvs/f62dfaaeace0d5c4aee4de872fea20b4 to your computer and use it in GitHub Desktop.
Save kvakvs/f62dfaaeace0d5c4aee4de872fea20b4 to your computer and use it in GitHub Desktop.
%%%-------------------------------------------------------------------
%%% @copyright (C) 2020, Erlang Solutions Ltd.
%%% @doc Create a long running process which consumes CPU periodically
%%% @end
%%%-------------------------------------------------------------------
-module(problem_cpu).
%% API
-export([start/0]).
start() ->
erlang:spawn(fun process_loop/0).
process_loop() ->
% 1 million empty cycles
counter(1000000),
% Sleep a little
receive after 250 -> ok end,
% More work?
process_loop().
counter(0) -> ok;
counter(N) -> counter(N - 1).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment