Previous | Next --- Slide 21 of 90
Back to Lecture Thumbnails
albystein

Is the barrier primitive only specific to parallel computing or is it used in other types of programming and computing models? I've seen a similar barrier primitive used in a different context when writing low-level code for device drivers. I don't know if they're both related in the way they're usage

yt1118

A barrier is a synchronization primitive, which is different from pthread_join() as mentioned in the lecture. pthread_join() blocks the calling thread until joining threads complete. Instead a barrier allows all threads to continue executing.

matteosantamaria

Hm, this barrier is an interesting concept, but I am a fairly experienced Python programmer and I haven't seen an equivalent in Python. I wonder if it is underused, or simply was never implemented in that language.

adamsiwiec

Could one use a semaphore as a certain type of barrier. E.g. All threads take a lock while they are doing their work, and then sping through a while loop that checks to see when they are all returned?

minglotus

@matteosantamaria A C++ programmer here :-) As far as I understand barrier is a common abstraction, so I did a quick search of keyword Python Barrier out of curiosity -> there is a barrier in Python with the same semantic (https://docs.python.org/3/library/threading.html#barrier-objects)

terribilis

Barrier synchronization seems pretty useful. With most synchronization variables the implementation of it is fairly simple. Semaphores are reasonably implemented with locks and some state variables. Would a barrier be implemented similarly? Perhaps you could use a condition variable along with a count variable that decrements when a new thread begins waiting and the condition is only met when count is 0.

Please log in to leave a comment.