lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


于 2011-11-14 15:21, Gerry Weaver 写道:
Hello All,

I'm looking at adding a Lua scripting capability to an existing C program. The program is basically a producer/consumer type model. It has one producer thread and multiple consumer threads. I'm looking for a way to copy arbitrary/opaque data from the Lua state in the producer thread to a Lua state in one of the consumer threads. The C code does not need to have any knowledge of the data. The producer simply passes a void pointer to the consumers. I have looked at the docs and I have seen several posts on the topic, but not found anything very useful. I've done some limited experimentation with the generic stack functions, but they are extremely slow. Would anyone have any interesting ideas on how I can accomplish this with decent performance?

Thanks,
-G





I'm not sure whether you mean native OS threads or Lua coroutines here by `producer thread' and `consumer threads'.

If you used Lua coroutines, I think it should be OK to simply use the lua_xmove API.

Or else, you should do some synchronization in C. And I found the Lanes[1] package would always be helpful in such cases.


-----------------
[1] http://kotisivu.dnainternet.net/askok/bin/lanes/