Calling C functions
Steven Schveighoffer
schveiguy at yahoo.com
Thu Dec 9 10:18:04 PST 2010
On Thu, 09 Dec 2010 12:24:05 -0500, Andrej Mitrovic
<andrej.mitrovich at gmail.com> wrote:
> On 12/9/10, Steven Schveighoffer <schveiguy at yahoo.com> wrote:
>> __gshared is unprotected sharing, and the type system is not aware that
>> it
>> is shared. Can you remember what specifically you were doing with the
>> variable?
>
> My dev PC is in repairs right now so I don't have the code atm. It's a
> project that works with audio devices and does some basic processing
> on audio data.
>
> But from what I can recall I would pass my D callback function to C,
> which would call the callback with an interrupt or very-high level
> priority thread (it depends on the device driver implementation) at
> many intervals per second. The D callback would do some processing,
> update one structure variable (e.g. struct "status"), and return.
> Inside main() I had an infinite loop which would wait for the device
> driver to stop calling the callback. One way of knowing if the device
> driver stopped is to check a flag inside the struct, e.g. a boolean
> status.done.
Multi-threadded code must do it's own handling of shared reads/writes to
__gshared data, such as protecting it with a mutex. Even with shared, it
does not guarantee multiple operations are atomic (for example reading two
members of a shared struct).
-Steve
More information about the Digitalmars-d-learn
mailing list