Возможно, стоит пояснить разницу между синхронизацией из thread/process-safe и синхронизацией с помощью Lock🤔
Наша задача — заставить разные процессы и потоки обращаться к базе данных (или любым другим ресурсам) последовательно. Чтобы не случилось так называемого race condition, то есть состояние гонки. Это когда разные потоки или процессы пытаются одновременно что-то сделать с одним и тем же ресурсом.
В этом случае нам нужна какая-то логика ограничения. Пока один процесс не завершил своё действие, другие не могут получить доступ к ресурсу.
Так вот, thread-safe и process-safe означает что отдельно взятые операции записи в БД гарантированно будут последовательны. Запросы из разных процессов или потоков выстроятся в очередь и не будут мешать друг другу. Лучше всего когда этот блок реализован на уровне БД в виде атомарных операций или ещё как-то.
Но зачем нам тогда еще дополнительный Lock?
Этот способ синхронизации используется когда процесс никак не укладывается в одно действие и должен сделать множество операций прежде чем дать доступ следующему. В этом случае процесс ставит некий глобальный Lock на ресурс и никто другой, даже получив законное право на доступ, не может ничего сделать. Все ждут пока этот Lock не будет снят.
Это решается на уровне приложения и правильность реализации полностью в вашей ответственности. Например, если забыли разблокировать или сделали перекрёстный Lock (Deadlock как на картинке), то всё зависнет в бесконечном ожидании.
#basic
Cholesterol protects the integrity of cell membranes and keeps cells healthy and strong. If a person’s cholesterol level were 0 (an impossibility), his cell membranes would be dry and cracked and all the cell content would leak out.
@googlefactss#humanbody
For most women (about 65%), the left breast is bigger than the right one. Researchers are unsure why, but they point to hormonal influences during development.
@googlefactss#humanbody
A human spinal cord stops growing in length around age four or five, while the vertebral column (spine) continues to grow until late adolescence or early adulthood.
@googlefactss#humanbody
In a condition called pelvic prolapse, a woman’s vagina can literally fall out and hang between the legs. Pelvic prolapse, however, can often be fixed..
@googlefactss#humanbody
[read more...]
The same skin cells that make up a human vagina are the same type of cells that are in a human mouth. The nonkeratinized stratified squamous epithelium are types of mucous membranes that are sensitive, absorbent, and continuously shed and regenerated.
@googlefactss#humanbody
It is common and normal for mothers to poop while giving birth. This often happens during the pushing stage because the muscles used to push a baby out are the same ones used to have a bowel movement.
@googlefactss#humanbody#nowyouknow
Occasionally, human corpses can undergo saponification, a process in which body fat transforms into adipocere through a chemical reaction. Adipocere has a consistency similar to semi-hard cheese and possesses a soapy feel. The most well-known example of this phenomenon is the "Soap Lady," a 140-year-old mummy showcased in Pennsylvania.
@googlefactss#humanbody#nowyouknow
Myth: The tongue is divided up into specific areas that are solely responsible for sensing certain tastes (e.g., sweet at the tip, bitter at the back)
Fact: The tongue's receptor cells that identify the molecules underlying the basic tastes (sweet, sour, salt, bitter and umami) are distributed on taste buds all over the tongue although some areas may be slightly more sensitive to certain flavors..
@googlefactss#humanbody#nowyouknow#mythbusted
[read more...]
Fingernail facts:
The middle finger’s nail grows the fastest while the smallest finger’s grows the slowest.
Nails usually grow faster on your dominant or more active hand (more use → more repair → more blood/nutrients) and speed up in summer thanks to better circulation.
Toenails grow slower.
Overall, males’ nails often grow faster than females’, but during puberty and pregnancy higher hormone levels make nails grow quicker in women.
[Source]
@googlefactss
#FunFact#HumanBody#nails