Возможно, стоит пояснить разницу между синхронизацией из thread/process-safe и синхронизацией с помощью Lock🤔
Наша задача — заставить разные процессы и потоки обращаться к базе данных (или любым другим ресурсам) последовательно. Чтобы не случилось так называемого race condition, то есть состояние гонки. Это когда разные потоки или процессы пытаются одновременно что-то сделать с одним и тем же ресурсом.
В этом случае нам нужна какая-то логика ограничения. Пока один процесс не завершил своё действие, другие не могут получить доступ к ресурсу.
Так вот, thread-safe и process-safe означает что отдельно взятые операции записи в БД гарантированно будут последовательны. Запросы из разных процессов или потоков выстроятся в очередь и не будут мешать друг другу. Лучше всего когда этот блок реализован на уровне БД в виде атомарных операций или ещё как-то.
Но зачем нам тогда еще дополнительный Lock?
Этот способ синхронизации используется когда процесс никак не укладывается в одно действие и должен сделать множество операций прежде чем дать доступ следующему. В этом случае процесс ставит некий глобальный Lock на ресурс и никто другой, даже получив законное право на доступ, не может ничего сделать. Все ждут пока этот Lock не будет снят.
Это решается на уровне приложения и правильность реализации полностью в вашей ответственности. Например, если забыли разблокировать или сделали перекрёстный Lock (Deadlock как на картинке), то всё зависнет в бесконечном ожидании.
#basic
Chanel Tapper holds the Guinness World Record for the longest tongue — 3.8 in (9.75 cm) — and says she loves watching people shriek in disbelief. She can remove Jenga blocks, grab a lemon from a glass, flip plastic cups, lift a spoon by curling it, and touch her nose and chin with the tip.
[Read more]
👅✨😲
@googlefactss#weirdfacts#worldrecords#humanbody#nowyouknow#funfact
There is a naturally occurring metal called gallium that melts in your hand. It has a melting point of about 29.8°C (85.6°F), so just holding it makes it turn from a shiny solid into a silvery liquid. Gallium doesn’t react with air, so it can sit in your hand safely, but it can melt containers made of aluminum. Scientists use gallium in electronics, LED lights, and solar panels because of its unique properties.
[Read more]
@googlefactss
#Science#WeirdFacts#Chemistry#DidYouKnow#Materials#Innovation
In Death Valley’s Racetrack Playa, large rocks, some weighing hundreds of kilograms, move across the dry lake bed, leaving long tracks behind. This happens when a rare set of conditions align. First, rain fills the lake bed with a shallow layer of water. At night, the water freezes into thin sheets of ice. As the sun warms the ground, the ice breaks into large, floating panels. Light winds then push the ice, slowly moving the rocks across the playa. The tracks left behind can last for decades, creating unique patterns. This natural process has been understood by scientists and is one of the most fascinating geological phenomena.
🪨❄️🌞
[Read more]
@googlefactss
#Nature#WeirdFacts#Geography#DidYouKnow#Deserts#Science#Mystery
There is a volcano in Indonesia called Kawah Ijen that glows bright blue at night. The blue glow comes from burning sulfur gases that ignite as they escape from the crater. Miners work in the area collecting solidified sulfur, even though the fumes are toxic. The effect makes the crater look like a surreal, electric-blue river flowing through the volcano, attracting photographers and adventurers from around the world.
🌋🔵🔥
[Read more 1]
[Read more 2]
@googlefactss
#Nature#WeirdFacts#Volcanoes#DidYouKnow#Science#Adventure#Indonesia
There is a place in the Sahara Desert called the Richat Structure, also known as the “Eye of the Sahara.” It is a giant circular formation nearly 50 kilometers wide, visible from space. Scientists believe it formed from erosion, exposing layers of rock in concentric rings. The structure is perfectly round, which makes it look like a massive bullseye in the desert. It has fascinated explorers and geologists for decades because of its unusual shape.
🎯🏜️🌍
[Read more]
@googlefactss
#Geography#WeirdFacts#Nature#DidYouKnow#Desert#Earth#Landmarks
Mammatus clouds look like a sky full of hanging pouches or bubbles. Their name comes from the Latin word “mamma,” which means “breast,” because of their rounded, pouch-like shapes. These clouds often appear after thunderstorms and can be bright white, gray, or even orange during sunset. Despite their dramatic appearance, they are mostly harmless and form when cold air sinks into warmer air below, creating the pouch-like shapes.
☁️🌅🌩️
[Read more 1]
[Read more 2]
Show your own mammatus cloud pictures, the one with the most likes gets added to the post. 😉
@googlefactss
#Nature#WeirdFacts#Weather#DidYouKnow#Clouds#Atmosphere#Sky