9 volatile int sensor_value;
14 void Handler_Sensors(FCGIContext *context, char *params)
16 const char *key, *value;
18 //Begin a request only when you know the final result
19 //E.g whether OK or not.
20 FCGI_BeginJSON(context, STATUS_OK);
21 while ((params = FCGI_KeyPair(params, &key, &value))) {
22 FCGI_JSONPair(key, value);
24 pthread_mutex_lock(&(data.mutex));
25 FCGI_JSONLong("sensor_value", data.sensor_value);
26 pthread_mutex_unlock(&(data.mutex));
30 void *SensorsLoop(void *arg) {
34 pthread_mutex_lock(&(data.mutex));
35 data.sensor_value = rand() % 1024;
36 pthread_mutex_unlock(&(data.mutex));
37 usleep(200*1000); //200ms
41 int main(int argc, char *argv[]) {
42 pthread_mutex_init(&(data.mutex), NULL);
43 //data.mutex = PTHREAD_MUTEX_INITIALIZER;
45 pthread_create(&data.sensors, NULL, SensorsLoop, &data);
46 FCGI_RequestLoop(&data);