Writing multithreaded ni-488.2 applications, Writing multithreaded ni-488.2 applications -9, Writing multithreaded – National Instruments NI-488.2 User Manual
Page 84: Ni-488.2 applications, Writing, Multithreaded ni-488.2 applications, Sectio

Chapter 8
NI-488.2 Programming Techniques
© National Instruments Corporation
8-9
// illustrates that.
ReadBuffer[ThreadIbcnt()] = ‘\0’;
// Convert the data into a numeric value.
sscanf (ReadBuffer, "%f", &Readings[ReadingsTaken]);
// Display the data.
printf(“Reading : %f\n”, Readings[ReadingsTaken]);
ReadingsTaken += 1;
if (ReadingsTaken >= 1000) {
return 0;
}
else {
// Issue a request to the device to send the data and rearm
// callback on RQS.
LocalIbsta = ibwrt (LocalUd, "SEND DATA", 9L);
if (LocalIbsta & ERR) {
printf ("ibwrt failed. No more callbacks.\n");
DeviceError = TRUE;
return 0;
}
else {
return RQS;
}
}
}
Writing Multithreaded NI-488.2 Applications
If you are writing a multithreaded NI-488.2 application and you plan
to make all of your NI-488.2 calls from a single thread, you can safely
continue to use the NI-488.2 global functions (
Ibsta
,
Iberr
, and
Ibcnt
).
The NI-488.2 global functions are defined on a per-process basis, so each
process accesses its own copy of the NI-488.2 globals.
If you are writing a multithreaded NI-488.2 application and you plan to
make NI-488.2 calls from more than a single thread, you cannot safely
continue to use the traditional NI-488.2 global functions without some
form of synchronization (for example, semaphores, mutexes, critical
sections). To understand why, refer to the following example.