You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm building a custom C dynamic library that I want to integrate with Luvi. My library uses libuv for asynchronous operations, and I want to ensure that it shares the same libuv event loop as Luvi to avoid conflicts and resource duplication.
Here's a simplified version of my C code:
#include<uv.h>#include<stdlib.h>#include<string.h>#include<pthread.h>#include<unistd.h>staticuv_async_t*luvi_async=NULL;
staticchar*message=NULL;
typedefstruct
{
char*data;
} async_data_t;
void*thread_func(void*arg)
{
// Wait for 1 secondsleep(1);
// Set the messageif (message)
{
free(message);
}
message=strdup("Hello from thread!");
// Send an async eventif (luvi_async)
{
printf("Sending async event\n");
uv_async_send(luvi_async);
}
returnNULL;
}
voidxx_init(void*async)
{
luvi_async= (uv_async_t*)async; // Store the uv_async_t*
}
voidxx_do_something()
{
pthread_ttid;
// Create a thread that sends an async event after 1 secondif (pthread_create(&tid, NULL, thread_func, NULL) !=0)
{
fprintf(stderr, "Failed to create thread\n");
return;
}
// Detach the threadpthread_detach(tid);
}
// Function to get the message, callable from Luaconstchar*xx_get_message()
{
returnmessage ? message : "";
}
Hi Luvi
I'm building a custom C dynamic library that I want to integrate with Luvi. My library uses libuv for asynchronous operations, and I want to ensure that it shares the same libuv event loop as Luvi to avoid conflicts and resource duplication.
Here's a simplified version of my C code:
and lua code
My main question is: How can I ensure that my dynamic library and Luvi link to the same libuv library and share the same event loop instance?
I'm looking for guidance on:
uv_async_t
handle from Luvi to my C library.Any help or pointers would be greatly appreciated!
Thank you.
The text was updated successfully, but these errors were encountered: