Hi,
I'm doing some tests using SDL2 (via Scheme Spheres bindings), and I'm having an issue related to multithreading. I want to generate audio procedurally, so what I need basically is access to an audio buffer that I can write on. SDL2 provides access to this buffer using a callback mechanism, which periodically invokes a provided function that is responsible for filling the buffer. This function is invoked in a separate thread of the main event loop. I implemented this callback function using c-define, but it eventually leads to a segmentation fault.
I understand that this is not possible using a single VM (based on [1]), but I have recently seen some discussion regarding multiple VMs on a single process [2]. Is this functionality available for testing? I know that for the moment it is considered alpha, but it could help for doing some preliminary tests. I intend to have the main program running on a Gambit VM, and for audio processing implement a C callback which will in turn invoke a function on a different Gambit VM (both created when the program starts, probably on a simple C initialization program). These VMs would communicate via message passing/sockets/etc.
For the moment I have the audio processing logic implemented in pure C, but I'd rather use Scheme for (almost) everything. This issue also arises in other asynchronous calls, for instance suspend/resume events on mobile platforms (Android specifically). I know that using multiple processes is an option on desktop versions, but I don't think I can create separate processes on Android.
Thank you!
Regards, Francisco
[1]: https://mercure.iro.umontreal.ca/pipermail/gambit-list/2006-June/000741.html
[2]: https://mercure.iro.umontreal.ca/pipermail/gambit-list/2014-February/007441....
Afficher les réponses par date
It is possible to have more than one GVM in one OS process, please see Marc's posting from the spring of 2012 I believe it was, with code attachment.
When you get this going please share your experience.
2014-03-30 23:02 GMT+02:00 Francisco fjvallarino@gmail.com:
Hi,
I'm doing some tests using SDL2 (via Scheme Spheres bindings), and I'm having an issue related to multithreading. I want to generate audio procedurally, so what I need basically is access to an audio buffer that I can write on. SDL2 provides access to this buffer using a callback mechanism, which periodically invokes a provided function that is responsible for filling the buffer. This function is invoked in a separate thread of the main event loop. I implemented this callback function using c-define, but it eventually leads to a segmentation fault.
I understand that this is not possible using a single VM (based on [1]), but I have recently seen some discussion regarding multiple VMs on a single process [2]. Is this functionality available for testing? I know that for the moment it is considered alpha, but it could help for doing some preliminary tests. I intend to have the main program running on a Gambit VM, and for audio processing implement a C callback which will in turn invoke a function on a different Gambit VM (both created when the program starts, probably on a simple C initialization program). These VMs would communicate via message passing/sockets/etc.
For the moment I have the audio processing logic implemented in pure C, but I'd rather use Scheme for (almost) everything. This issue also arises in other asynchronous calls, for instance suspend/resume events on mobile platforms (Android specifically). I know that using multiple processes is an option on desktop versions, but I don't think I can create separate processes on Android.
Thank you!
Regards, Francisco
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
I have not found the post you mention. Based on https://mercure.iro.umontreal.ca/pipermail/gambit-list/2014-February/007441...., I understood it was a work in progress... If you remember the thread, it would be great.
Has anyone faced a similar situation regarding asynchronous callbacks? Do you have any suggestion about handling that situation (maybe a different approach than the one I proposed)?
Thank you!
Regards, Francisco
On Mon, Mar 31, 2014 at 3:18 AM, Mikael mikael.rcv@gmail.com wrote:
It is possible to have more than one GVM in one OS process, please see Marc's posting from the spring of 2012 I believe it was, with code attachment.
When you get this going please share your experience.
2014-03-30 23:02 GMT+02:00 Francisco fjvallarino@gmail.com:
Hi,
I'm doing some tests using SDL2 (via Scheme Spheres bindings), and I'm having an issue related to multithreading. I want to generate audio procedurally, so what I need basically is access to an audio buffer that I can write on. SDL2 provides access to this buffer using a callback mechanism, which periodically invokes a provided function that is responsible for filling the buffer. This function is invoked in a separate thread of the main event loop. I implemented this callback function using c-define, but it eventually leads to a segmentation fault.
I understand that this is not possible using a single VM (based on [1]), but I have recently seen some discussion regarding multiple VMs on a single process [2]. Is this functionality available for testing? I know that for the moment it is considered alpha, but it could help for doing some preliminary tests. I intend to have the main program running on a Gambit VM, and for audio processing implement a C callback which will in turn invoke a function on a different Gambit VM (both created when the program starts, probably on a simple C initialization program). These VMs would communicate via message passing/sockets/etc.
For the moment I have the audio processing logic implemented in pure C, but I'd rather use Scheme for (almost) everything. This issue also arises in other asynchronous calls, for instance suspend/resume events on mobile platforms (Android specifically). I know that using multiple processes is an option on desktop versions, but I don't think I can create separate processes on Android.
Thank you!
Regards, Francisco
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
On Apr 1, 2014, at 10:06 AM, Francisco fjvallarino@gmail.com wrote:
I have not found the post you mention. Based on https://mercure.iro.umontreal.ca/pipermail/gambit-list/2014-February/007441...., I understood it was a work in progress... If you remember the thread, it would be great.
Here is an example that uses the multiple VM support. I’ve tested it on OS X only, but it should be portable to other OSes.
You first have to build Gambit with
./configure --enable-multiple-vms make
And then
cd multiple-vm-example make
then
telnet localhost 12345
to connect to the VM that is created.
There are still issues with the multiple VM support, notably the VMs share a single console, which means there are race conditions if you try to read/write things to the console from different VMs. This is why the example code runs one of the VMs on a network connection (which is probably what you want to do anyway in practice).
Marc
Marc,
Thank you for the example! This will definitely allow me to run multiple threads to separate UI from audio processing.
I will try to dig a bit deeper to understand how the VMs work. One of the things I need to do is invoking a function on a specific VM (to generate audio I need to register a C callback that is invoked on a thread that is not controlled my me). My plan is having a standard VM running the main program and have another "idle" VM that will only be invoked by the C callback function. This way I should avoid corruption of the main VM stack. This idle VM would receive the information it needs from an in process message queue or a socket. If I can find the way of invoking the function on the right VM, I think my problem would be solved.
Thank you!
Regards, Francisco
On Sat, Apr 5, 2014 at 12:17 PM, Marc Feeley feeley@iro.umontreal.cawrote:
On Apr 1, 2014, at 10:06 AM, Francisco fjvallarino@gmail.com wrote:
I have not found the post you mention. Based on
https://mercure.iro.umontreal.ca/pipermail/gambit-list/2014-February/007441...., I understood it was a work in progress... If you remember the thread, it would be great.
Here is an example that uses the multiple VM support. I've tested it on OS X only, but it should be portable to other OSes.
You first have to build Gambit with
./configure --enable-multiple-vms make
And then
cd multiple-vm-example make
then
telnet localhost 12345
to connect to the VM that is created.
There are still issues with the multiple VM support, notably the VMs share a single console, which means there are race conditions if you try to read/write things to the console from different VMs. This is why the example code runs one of the VMs on a network connection (which is probably what you want to do anyway in practice).
Marc
Hi!
Am 01.04.2014 um 16:06 schrieb Francisco fjvallarino@gmail.com:
Has anyone faced a similar situation regarding asynchronous callbacks? Do you have any suggestion about handling that situation (maybe a different approach than the one I proposed)?
I have almost no experience with gambit, but on other platforms / languages, I usually write an actual callback in C that does feed an „event“ / signal (whatever it is called in scheme) into the VM that is executed on the vm thread / as a lightweight thread. Depending on the requirements of the callback (it might to might not require the buffer to be filled immediately after the callback returns), this might be an option checking out.
Cheers, Dirk