[erlang-questions] [Q] erlang:check_process_code/2

Ladislav Lenart lenartlad@REDACTED
Fri Apr 18 10:16:28 CEST 2008


Bjorn Gustavsson wrote:
> Ladislav Lenart <lenartlad@REDACTED> writes:
> 
>> Hello,
>>
>> I think I run into trouble with code purge/delete machinery. To solve
>> this puzzle, I need to understand how erlang:check_process_code/2
>> works. Could anyone please tell me under which circumstances this
>> function returns true? I know that it is "when a process is executing
>> old code" but what does that really mean (for example, what if the
>> process references a Fun from that module,...)?
> 
> Yes, if a fun references old code, erlang:check_process_code/2 will
> return true.

Thanks. I understand it this way: If a process holds in its internal state
a reference to a fun that itself references old code, check_process_code/2
will return true for it. The process does not have to be evaluating the fun.

To confirm this, I implemented a trivial process that can store a Fun sent
to it and did the following "test":
  1. P = fun_proc:start(),
  2. P ! {'fun', SomeFun},
  3. code:purge(SomeMod),
  4. code:delete(SomeMod), % make current version of SomeMod old
  5. false = erlang:check_process_code(P, SomeMod).

I tried the above for `SomeFun = fun SomeMod:f/0' and also for `fun f/0'
(using another function from `SomeMod'). But both return false.

So I either misunderstood you or my above "test case" is wrong. Could you
please shed some light on this for me?

Thanks again,

Ladislav Lenart





More information about the erlang-questions mailing list