CallBackStreaming threading concurency

Post your C and C++ discussions here
Post Reply
bennog
Active User
Active User
Posts: 33
Joined: Mon Nov 26, 2012 9:16 am
Location: Netherlands

CallBackStreaming threading concurency

Post by bennog » Wed Jun 28, 2017 8:57 am

I was looking at the PS4000 streaming functions and noticed the following.

in the CallBackStreaming function the global variables g_sampleCount and g_ready are set before the data is copied to the application buffers.

In single threaded applications (and the pico core is also single threaded) this won't be a problem.
In multi threaded application this will produce corrupted data depending on what thread runs when.
It won't crash the application, because all memory locations are ok, but the data can be partly new data and partly old data, what part is old and what is new is depending on the implementation of memcpy library function.

The same construction is uesed in most of the other SDK samples also.

Benno

Hitesh
Site Admin
Site Admin
Posts: 2811
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: CallBackStreaming threading concurency

Post by Hitesh » Mon Jul 03, 2017 2:56 pm

Hi Benno,

Thank you for the feedback.

The example for the ps4000 driver has been updated on our GitHub repository and we will review the other examples as well.

The examples provided are for guidance and can be modified to suit the end application. You can also submit Pull Requests on GitHub and we will review suggested changes.

Regards,
Hitesh

Technical Support Engineer

Post Reply