lua-users home
lua-l archive

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


I've currently tried to use these. I have implemented the lock & unlock
with critical section. You must pay attention to some stuff :

- I thinks the code in ldump is buggy. I do not have found any reason for
it and it was crashing.
- In lua_close, lock is called without corresponding unlock.
- Any call to lua method lock the critical section.

A good idea is to store it in the state and use luai_userstate* to work
with it. If you yield the thread, you need to pay attention to lock and
unlock inside luai_userstateyield and resume.

for example an implementation can be ( while not tested )

#define luai_userstateopen(L) InitializeCriticalSection( lua_getuserdata(
L ) )
#define luai_userstateclose(L) DeleteCriticalSection( lua_getuserdata( L ) );
#define lua_lock(L) EnterCriticalSection( lua_getuserdata( L ) )
#define lua_unlock(L) LeaveCriticalSection( lua_getuserdata( L ) )

lua_userdata can be define as fromstate() using LUAI_EXTRASPACE

If you have any other questions, feel free.

Julien Hamaide
Engineering Coach
10tacle belgium

> Hello, I read lua sources at tonight. I saw this code piece:
>
> ldump.c  line 33-35:
>   lua_unlock(D->L);
>   D->status=(*D->writer)(D->L,b,size,D->data);
>   lua_lock(D->L);
>
> why lua_unlock before lua_lock?
>
> I find lua_lock and lua_unlock defined in Llimits.h:
>
> Llimits.h 109-112:
> #ifndef lua_lock
> #define lua_lock(L)     ((void) 0)
> #define lua_unlock(L)   ((void) 0)
> #endif
>
> I think lua_lock and lua_unlock is unusable, for new version?
> who can let me know something about this?
>
> THKS.sorry for my poor english.I am chinese.
>