Best way to check if a semaphore is deleted?

Hey all,

Was just wondering about what the best way to check if a semaphore has been deleted? I’ve found that when deleted, the semaphore handle is assigned a value of 0x20000558, but when checking in a if statement, I get a warning that it’s a comparison between a pointer and integer. Ideally I’d like to get rid of that warning, but if there’s a better way of verifying, please let me know!

SemaphoreHandle_t xBinarySemaphore;
xBinarySemaphore = xSemaphoreCreateBinary();
if (xCounting == 0x20000558){


THe handle for a semaphore does not change when it is deleted, it just now points to memory not reserved for a semaphore. There is NO way to 100% accurately test if a semaphore handle has been deleted, because there could very well be another object, even another semaphore recreated at that same address.
This is just like you can’t tell if a pointer that was gotten from malloc has already been free’d.
You need to keep track of the life time of these things yourself. I personally try to avoid deleting things like that to avoid the problem.
The only real way to handle it is not delete the semaphore until everyone who might want to touch it either has gotten rid of its copy of the handle or at least knows the handle isn’t valid anymore, THEN you can delete the object.

Sounds good, thanks for the insight!