Пример #1
0
static int lua__uniq_inuse(lua_State *L)
{
	struct handlemap * h = CHECK_UNIQ(L, 1);
	handleid id = (handleid)luaL_checkinteger(L, 2);
	void *p = handlemap_grab(h, id);
	lua_pushboolean(L, p != NULL);
	return 1;
}
static void
grab(struct handlemap *m, int thread) {
	int i;
	for (i=0;i<HANDLE_N;i++) {
		int r = rand() % (i+1);
		handleid id = pool[r];
		void *ptr = handlemap_grab(m, id);
		printf("thread %d: grab %d, id = %u, ptr = %p\n", thread, r, id, ptr);
		usleep(50);
		if (ptr) {
			ptr = handlemap_release(m, id);
			if (ptr) {
				printf("thread %d: release %d, id = %u, ptr = %p\n", thread, r, id, ptr);
			}
		}
	}
}