dll - Aaccessing the same information from multiple places in C -


i want able call 2 functions both use information stored in variable foobar. have 2 functions foo , bar, both perform operation on variable foobar. foo writes value while bar reads it. these functions intended in library (dll) return value calling program. data accessed mixture of arrays/pointers arrays, doubles , ints.

would people able point me in right direction achieving such operation?

or looking @ how acquire data in wrong way, , there better way of doing this?

regards

the basic approach be:

volatile my_int;  void foo(void) {     my_int++; }  void bar(void) {     if (my_int)         ...     else         ... } 

however, want achieve this? reference counting of sort? or my_int supposed external library , hence needs "acquired"? in case, might want pass pointers library or use structures pass each call.

it depends on whether or not library code needs have internal state. if there no internal state , functionality rests solely inside calls foo , bar, should pass appropriate data along it.

else, might want have library initialization code , queue buffers , register callback functions user program library acts upon.

edit: if question race conditions:

you need able write data type atomically , read atomically. have non-critical race condition. if need act on objects, arrays whole, need use mutual exclusion (mutex) locks. lock need type can read/written atomically , function foo acquire lock, edit data, release lock. function bar same. on parallel systems need hardware support test-and-set commands, or can still run live-lock.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -