[FieldTrip] questions about realtime buffer
r.oostenveld at donders.ru.nl
Mon Jun 6 21:18:53 CEST 2011
> I’m implementing a realtime buffer in C++ pretty much like in “demo_combined” : my application creates a buffer server and an acquisition client.
> I encountered a first problem when trying to close the buffer server cleanly, but with some small changes in tcpsocket.c and tcpserver.c, I think I solved the problem.
> If these modifications can be useful for other users and do not create other problems, I will share them.
If you have changes that don't break the ANSI-C compilation then I am certainly happy to include them in our version. Please go to http://bugzilla.fcdonders.nl and submit a bug/request in which you attach the updated files.
> I encounter now a new problem : what if there are several acquisition clients ?
> I tried to create several couples “buffer-server + acquisition client” in different threads in my application, but it does not work at all, because of global variables (I suppose).
> It seems that one buffer server can not manage several acquisition clients, but I’m not sure of this point.
> Did anyone encounter this problem (or solve it) ?
> Or do anyone have an idea ?
You are right about the global variables. The buffer is implemented using multithreading and to ensure that incoming data (Write) does not interfere with outgoing (read) data a mutex (http://en.wikipedia.org/wiki/Mutual_exclusion) is set. That mutex is shared throughout the code so that all pieces of code are aware of when they are allowed to change the buffer content.
Having multiple buffers would require multiple mutexes and multiple (separately identifyable) memory segments for the actual data. That would require a lot of changes to the code.
You can run multiple buffers on the same computer, but you would have to start them separately and they would have to have different TCP ports. The application you are writing could write different aspects to the different TCP ports. You can use fieldtrip/realtime/general/buffer.exe, which in fact is a compiled version of fieldtrip/realtime/buffer/test/demo_buffer. Note that you would use it as
buffer.exe localhost 2340
buffer.exe localhost 2341
buffer.exe localhost 2342
buffer.exe localhost 2343
to start 4 buffers on ports 2340-2343. The "localhost" argument is not used, but still appears to be required according to the demo_buffer.c source code. Of course it is cumbersome to have to start the 4 seperate processes on top of your own application. On unix-like computers you should be able to write a single application that at the beginning forks into a parent and child, where the parent continues as your application and where the child (which is then a separate process) can start the buffer. You can fork multiple times, to have multiple buffers (one per child).
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fieldtrip