[FieldTrip] questions about realtime buffer

SERPOLLET Amélie 228173 amelie.serpollet at cea.fr
Thu Jun 9 10:52:42 CEST 2011


Dear Robert, 

 

Thank you for your answer. I was trying to run several buffers in the same process, but running them in different processes as you describe it seems to be very easier.

The modifications I did to close the buffer cleanly make possible to run a new buffer after closing one, in the same process. 

Maybe it is not necessary if buffers are created in different processes, but they are few modifications and I find it is still convenient, so I submit it.

 

Best regards

Amélie

 

________________________________

De : Robert Oostenveld [mailto:r.oostenveld at donders.ru.nl] 
Envoyé : lundi 6 juin 2011 21:19
À : Email discussion list for the FieldTrip project
Cc : SERPOLLET Amélie 228173
Objet : Re: [FieldTrip] questions about realtime buffer

 

Dear Amelie

 

	

	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).  

 

best

Robert

 

 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20110609/82866310/attachment.html>


More information about the fieldtrip mailing list