thesecretmaster / predis-v0

Like redis, but parallel and written from scratch for fun!
GNU General Public License v3.0
1 stars 0 forks source link

Make thread_info_list deletion safe #12

Closed thesecretmaster closed 5 years ago

thesecretmaster commented 5 years ago

This isn't a horribly hard task, we'll need need to add a "semaphor" (I think that's the right term?) to main_struct. Every time a thread beings using the array (read, write, whatever) it increments the field, every time it leaves, it decrements it.

There will also need to be a single bit write lock. When someone wants to delete from the list, they set the write lock and wait for the semaphor to become 0. Any readers or writer will spin on this lock before touching the semaphor. Readers will just spin if it's 1, writers will spin and try and increment it themselves.

The performance impact on anything using the thread_info_list will be fairly serious, but the only thing that uses it is the clean job which has unpredictable performance characteristics anyways because it spins on the safe field.