New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrate re_main in to custom main loop #117
Comments
Yup, docs are an issue. Here is an example how re can be used in a thread. You are probably aware that you will have to acquire some lock when communicating with that thread from another one. You can do so with As you can see in the examples, I have not used RAWRTC with threads so far, so I would be interested to see if it works out for you. If you are using a different event loop, an alternative would be to make it compatible to the re event loop or the other way around. @ruengeler has applied some patches to re to make it run in a libuv event loop but this hasn't been merged so far. Still, if you're interested, ping me. |
Thank you for the response. I've been trying with your example but I'm getting problems locking re. I'm not sure witch functions i have to re_thread_enter/re_thread_leave. Rawrtc does this internally in some places? I'm also getting this output error "main: re_lock: Resource deadlock avoided", probably for what you say that is not reentrant right? Any examples about re_set_mutex? If you have some more information/examples about this it will be awesome. About what you said on using a different event loop, I was looking how re_main was working internally and it seems a bit of heavy lifting to implement it in my event loop. Also I'm not really sure about performance on running in the same main thread, I'm a bit scared of some unwanted waitings inside rawrtc/re. |
The master branch of RAWRTC does some locking internally (at the moment at least, I'm planning to remove this). Since it also uses Check out re's docs or the code. The mutex is of type Example (untested): int err;
pthread_mutex_t mutex;
pthread_mutexattr_t mutex_attribute;
// Initialise and set mutex attribute
err = pthread_mutexattr_init(&mutex_attribute);
if (err) {
DEBUG_WARNING("Failed to initialise mutex attribute, reason: %m\n", err);
return rawrtc_error_to_code(err);
}
err = pthread_mutexattr_settype(&mutex_attribute, PTHREAD_MUTEX_RECURSIVE);
if (err) {
DEBUG_WARNING("Failed to set mutex attribute, reason: %m\n", err);
return rawrtc_error_to_code(err);
}
// Initialise mutex
err = pthread_mutex_init(&mutex, &mutex_attribute);
if (err) {
DEBUG_WARNING("Failed to initialise mutex, reason: %m\n", err);
return rawrtc_error_to_code(err);
}
// Apply the mutex
re_set_mutex(&mutex);
// Store that mutex somewhere
// ... |
I could make a little test to run this way and for now it seems to work. I will have to develop further to keep testing. By the way, at some point I will have compile this on windows (now I'm on arch linux), and going throw the code it seems that it is only implemented for pthreads right? I have to supply a custom pthread library for windows to work? Thanks a lot for such help. |
To be honest, I don't know since I never tried to compile it on Windows. But the code of re is limited to pthread, so I assume you will have to find a pthread-compatible library for Windows. |
Libuv has interface for epoll / poll fd communications to other events outside of libuv ecosystem. |
@junky89 or could be used the mqueue from libre lib. |
Hi,
For several days I tried to run rawrtc on top of my game loop without luck. I'm not able to find any resource, documentation or example on how to proceed with this (all examples are using re_main in the main thread). My aproches has been so far trying to run re_main in another thread, and it's "kind" of working but I think I'm not doing it right.
Someone know how to accomplish this? Some example or direction will be really welcome because I'm kind of stuck.
Thanks.
The text was updated successfully, but these errors were encountered: