Segmentation Fault Error in Concurrent Sensor Data Processing Simulation: What's the Issue?

My code is supposed to simulate a system where multiple sensors collect data concurrently and process them. But I get this Segmentation fault (core dumped) error thrown in my console as the code crashes. Please what am I doing wrong ?
attachment 0
attachment 1
Solution:
Seems like your
pthread_create()
pthread_create()
does not receive the correct argument, which should be the address of the SensorData struct, not the address of the value field within the struct. This part of your code : ```...
Jump to solution
2 Replies
Solution
Joseph Ogbonna
Joseph Ogbonna•8mo ago
Seems like your
pthread_create()
pthread_create()
does not receive the correct argument, which should be the address of the SensorData struct, not the address of the value field within the struct. This part of your code :
rc = pthread_create(&sensor_threads[t], NULL, sensor_task, (void *)&sensor_data[t].value);
rc = pthread_create(&sensor_threads[t], NULL, sensor_task, (void *)&sensor_data[t].value);
Change it to pass the address of the SensorData struct instead:
rc = pthread_create(&sensor_threads[t], NULL, sensor_task, (void *)&sensor_data[t]);
rc = pthread_create(&sensor_threads[t], NULL, sensor_task, (void *)&sensor_data[t]);
Marvee Amasi
Marvee Amasi•8mo ago
How did not see this🥲, thanks @Joseph Ogbonna
Want results from more Discord servers?
Add your server