RE: [BUG?] Segmentation fault in lua_error() - easily reproducible

  • From: William Adams <william_a_adams@xxxxxxx>
  • To: <luajit@xxxxxxxxxxxxx>
  • Date: Sat, 13 Dec 2014 21:13:35 -0800

This argument has devolved into a slapping fight.

Can you please move on, or get back to a point where meaningful help can be 
offered.


Sent from my Windows Phone
________________________________
From: Sergei Zhirikov<mailto:dmarc-noreply@xxxxxxxxxxxxx>
Sent: ‎12/‎13/‎2014 1:44 PM
To: luajit@xxxxxxxxxxxxx<mailto:luajit@xxxxxxxxxxxxx>
Subject: Re: [BUG?] Segmentation fault in lua_error() - easily reproducible



>> Wait, I misread the docs, again.
> misread how?  AFAICT, the docs about lua_resume() state that it
> starts/resumes a coroutine, nothing else.  the given code puts a
> function that calls coroutine.yield(), but it never builds a coroutine
> (either by coroutine.create(f) or lua_newthread())


If we are going to refer to the docs, let's read them precisely.
The docs say that lua_resume() "Starts and resumes a coroutine in a given 
thread." Which:
    1. Clearly indicates that a coroutine is not the same as a thread, but 
rather something that runs in a thread.

    2. Does NOT say that the thread must be created by a call to 
lua_newthread().

So, the code in question start a coroutine (represented by the loaded function) 
in the main Lua thread. You don't "build" a couroutine, because there is 
nothing to build. You need a thread and a function and a call to lua_resume() - 
that's all there is to it. If you feel that a coroutine is something more than 
that - that's just your imagination, because it isn't.

The Lua API to manipulate coroutines may give one a different impression, as it 
is slightly higher level than the C API. When using Lua API you have to create 
a new thread, which coroutine.create() does internally, for that simple reason 
that it is the only thing that makes sense, because the existing thread is 
already occupied running the very code that is trying to start a new coroutine 
- this has nothing to do with the nature of the coroutine as such. When using 
the C API, such a restriction does not exist.

Other related posts: