Hacker Newsnew | past | comments | ask | show | jobs | submit | hackworks's commentslogin

Did you install XP first or Linux?

The prescribed order was to install XP and then Linux on a different device/partition. Linux would install Grub or LILO in MBR with dual boot options.

Hence, the easy way to clean up Grub or LILO was to boot into DOS from a CD or floppy and run ‘fdisk /mbr’


Most common use case for concurrency is for IO intensive workloads. When it comes down to IO, programming language hardly matters.

If you have CPU intensive workload, an optimizing compiler can help. Well, for that you have C or other languages with more mature and aggressive compilers.


The intermittent disruption of services is death by 1000 cuts. Read the Zynga story.

http://wrongtool.kostadis.com/firewalls-killed-zynga/


Well, there is a well defined pattern using configure and make. When very complex builds like GNU Emacs and operating systems have done quite well with this pattern, I wonder what problem we are trying to solve.


That's a very apple to oranges comparison, wouldn't you agree?

GNU autotools assists in making source code packages portable accross Unix-like systems, while make is for build automation and has fine-level dependencies (inter-files).

Nix is a package manager, and though is can build your software for you transparently, it is not tied to and specific software configurationand building toolset, can manage buildtime and runtime dependencies (including downloading the sources), caching build results transparently, etc.


Not an expert here.

In a spin lock, the lock state is checked in a tight loop by all waiters. This will be using some sort of memory fence. FWIK, memory fence or barriers flush the CPU cache and would initiate reading the variable (spin lock state) for evaluation. I would expect spin locking overheads to increase with number of cores.

On NUMA, I think flushing is more expensive. Hence, spin locks have an additional overhead of having to load and evaluate on every spin as against being woken up for mutexes (like a callback)


Yes, spin locks require atomic memory operations - as do many other OS primitives. CPUs have dedicated instructions to do this more quickly for locks than generalized coherent memory, for example cmpxchg on x86. There are microarchitectural optimizations to make these things work well.

I've been writing MP code since the early 90's; SPARC, MIPS, x86, PPC, SH-4, Alpha, and all have instructions to make this easier for you.

Spin locks are very useful for locks held for short durations, and only on MP systems, particularly in the kernel, since a spin lock there can deadlock the whole system on a single CPU machine. The very general rule of thumb is that you generally want blocking locks, unless there is a very specific reason to use a spin lock. Those very specific reasons might be waiting briefly on some device in a driver, or running a realtime system where wake latency is critical, etc. Most of the time, spin locks will burn CPU for no good reason, and you still have to implement the non-spinlock case anyway, in case you are running on a 1 CPU system. So, might as well start with blocking locks, and only add spin locks where performance would benefit from it.


It doesn’t flush the entire cache (that would be a disaster) but it does shoot down the cache line containing the lock in all cores other than the one that acquired the lock.

The real issue with spin locks is fairness. There’s no assurance that any given thread will ever make progress. A thread could starve forever. Production-ready mutexes like absl::Mutex make efforts toward fairness, even if they don’t have hard guarantees.


> but it does shoot down the cache line containing the lock in all cores other than the one that acquired the lock.

Well, as long as you do the test-CAS instead of the pure-CAS approach not every loop iteration results in cache line bouncing.

Plus intel has introduced the MWAIT[0] instruction to implement something similar to futex in hardware, i.e. the hyperthread can sleep until another core updates the cacheline in question.

[0] https://www.felixcloutier.com/x86/mwait


That's true, though MWAIT can only be used from kernel mode. At least the docs say that you get a #UD exception if you attempt to use it from user mode.


Right, there's UMWAIT[0] for that, but that's quite new.

[0] https://www.felixcloutier.com/x86/umwait


Aren't most modern spinlock implementations are ticket-based, which ensures fairness among waiters (FIFO-like)? The linux kernel implementations most definitely are.

I agree that the naive implementations are not.


Completely fair locks can have extremely terrible throughput performance, so depending what you are doing with them, they might not be a good idea...


> checked in a tight loop by all waiters

This actually does not have to be this way. You could have a linked list of spinlocks, one for each waiter. Each waiter spins on its own, unique spinlock. When the previous waiter is done it unlocks the next spinlock, and so on. The implementation gets a bit complicated on non-GC languages, since there are races between insertion/removal on the linked list. If the number of threads is fixed and long-lived then it becomes easier, since instead of a linked list you can have an array of spinlocks.

Note: in some architectures (x86?) you could possibly do away with atomics, since (I believe) int updates are atomic by default. Not really sure though.


Yep, that's the underlying principle behind Mellor-Crummey Spinlock: https://lwn.net/Articles/590243/.


Yes! The MCS spinlock, the name eluded me. The paper is actually a pretty good read (it is linked in the lwn article).


> you could possibly do away atomics, since (I believe) int updates are atomic by default.

The release can be a compiler only barrier followed by a simple store, but you do need an atomic RMW in the acquire path.

It is technically possible to implement a lock with just loads and stores (see Peterson lock[1]) even in the acquire path but it does require a #StoreLoad memory barrier even on Intel, which is as expensive as an atomic RMW so it is not worth it.

Edit:fixed barrier name typo.

[1] https://en.m.wikipedia.org/wiki/Peterson%27s_algorithm


> #StoreRelease memory barrier even on Intel

What is that? x86 is TSO...

Do you have an example of the full acquire and release sections in x86 assembly?


I'm sorry, I meant #StoreLoad.

Edit: here is a good (but long) article with a x86 Peterson Lock example (with an analysis of the critical race without the barrier):

https://bartoszmilewski.com/2008/11/05/who-ordered-memory-fe...


NetApp has a very interesting implementation RW spin lock inside the kernel. I tried optimizing to make it more fair for writers by introducing a single variable that would be check in each iteration.

The additional delay it added for checking the state resulted in deadlock timer triggering a dump! Hence, checking a variable is very expensive.


If you're interested in very efficient MCS style reader writer locks, check out this paper:

https://people.csail.mit.edu/mareko/spaa09-scalablerwlocks.p...


Most software companies I have worked for, encourages filing patents just to build their arsenal and increase their market value in times of acquisitions or patent wars. They are not focused on creativity, innovation or advancement.

I have seen a patent to use SSH to administer a storage system! It was just depressing and sad to see such patents granted and the inventors bragging about it.


> I have seen a patent to use SSH to administer a storage system

People should be embarrassed.

So many nerds have this self-image of being a change-the-world conquering intellect, and then spend their day trying to game a bullshit system to pull a few bucks from their neighbor's pocket. And they're not capable of actually making anything, so they try to patent bog-standard uses of other people's tools.

Their bragging about it is a blessing, though. Makes them easier to avoid.


As long as there are no rounded corners, ya.

Sent from my i-branded device


That was my resolution a couple of months back. Signed off from Facebook, Instagram, Twitter and Reddit (never was on any other platform making crazy things with your snaps). Retaining accounts on HN and GitHub.

I miss nothing, actually feel good staying away from all the toxic comments on Twitter.

I did not need Light Phone or burn a hole in my pocket to achieve this. Plain simple determination.


Analogous to “putting all eggs in a single basket”, the risks are very high.

You end up becoming hyper sensitive at work, start taking everything personal -well, it is your identity or ego at stake. Leads be becoming very closed, guarded and aggressive. Everyday becomes a fight for survival.

I personally went through this phase for a long time. Looking back, some of my managers exploited this by reinforcing. They knew if they compare me with anyone, I would up the competition and perform even better. This did not cost them money since I had invested myself, my identity and ego 100%. Overall, resulted in a highly competitive team but extremely stressful and caustic!

After changing teams, I decided to take a step back and make a fresh start. I now work for the love of my work and do not let it represent who/what I am. It is my identity at work. Back home or with friends, I have a different identity. Having multiple things to fallback has made me more resilient and lot more positive.


I wonder if it is an age thing. Paraphrasing but there is a quote along the lines of the difference between experienced people/managers and inexperienced people is they know which battles to fight. Sadly this is a right of passage, you need to fight the wrong battles first before you realise this. I am in my forties now and so much better at selecting which battles to fight.


You’re absolutely right. Around this age if not a bit earlier people have seen/experienced enough to see things more clearly. I wonder if this is the reason most SV companies prefer fresher meat.


Might also be why companies prefer youngsters over people who are 40+. The opportunity for exploitation is higher.


Same thing happened to me. I realized that I actually do better work now that I'm more chilled out and my life is more balanced.


Schools and colleges should ideally be a place for creativity, free thinkers and open by default.

Using surveillance and improving attendance through fear tactics is not going to help. You will get their physical presence but not their involvement.

I wonder how long it will take for students to start placing check Bluetooth devices in all places they are expected to be present and remotely switch them at desired times. I hope this happens and defeats this unethical forced surveillance by colleges.

Alternatively, I would encourage student counselors spend a little more time with students and assist them to monitor themselves. Motivate the youngsters to better regulate themselves and grow up to be independent and responsible adults.

Note: On Android, there is an app named Tasker. You can automate your phone with it. Schools could start maintaining shared Tasker profiles that can help students stick to some well defined and commonly followed routines. This is giving control back to the student and coaching them about the merits in planning and sticking to plans.


Thank you very much for the wonderful and very insightful article.

Developing the humility and truly believing that we are all snowflakes and willingness to learn from the diversity around us is a big step forward.

I loved the analogy between leaders and bridge builders. I always considered leaders as those who build a pedestal or platform or ladder for the rest to use and grow. Very similar.

It gives me confidence and courage to take up a few courses myself and enjoy learning and not just go after grades.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: