Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Home NTDEV
Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging


The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.


Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/


How many spinlocks can I create?

Alex_FunkyAlex_Funky Member - All Emails Posts: 171

Is there any limit on the number of spinlocks created for my driver? Or am I not restricted? Or it's dependent on the kind of spinlock?

Comments

  • Don_BurnDon_Burn Member - All Emails Posts: 1,711

    There is no limit to spin locks. Just be sure you have a locking hierarchy so that you don't get deadlocks of thread 1 holding lock A and trying to get lock B, while thread 2 holds lock B waiting to get lock A.

  • Dejan_MaksimovicDejan_Maksimovic Member - All Emails Posts: 350
    via Email
    A spin-lock is just an int variable, so the limit is the amount of
    memory available, literally.
    It is also the worst way of synchronizing stuff, and should be used
    ONLY if no other way exists.

    > Is there any limit on the number of spinlocks created for my driver? Or am I
    > not restricted? Or it's dependent on the kind of spinlock?
  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 8,089
    edited October 18

    It is also the worst way of synchronizing stuff, and should be used ONLY if no other way exists.

    Nonsense.

    Please tell me which sync primitive has lower overhead in the uncontested acquisition path.

    Peter

    Peter Viscarola
    OSR
    @OSRDrivers

  • Dejan_MaksimovicDejan_Maksimovic Member - All Emails Posts: 350
    via Email
    How often are locks uncontested?
    But you have a point... when contention is unlikely, the cost of most
    others sync mechs is higher.


    When possible, I would still go for atomics vs. spinlock, or RW locks in
    terms of performance.



    Please tell me which sync primitive has lower overhead in the uncontested
  • anton_bassovanton_bassov Member MODERATED Posts: 5,180

    It is also the worst way of synchronizing stuff, and should be used ONLY if no other way exists.

    Well, it is the "worst" in a sense that a CPU cannot do anything (apart from processing interrupts, of course) while spinning in a do-nothing loop while trying to acquire a lock. Therefore, it should be, indeed, used judiciously. OTOH, as long as you don't hold it for too long (no pun intended), it is the most efficient synch construct in existence, especially if we take into account that synchronisation on any dispatcher-level synch construct is invariably going to involve spinlock acquisition behind thescenes

    When possible, I would still go for atomics vs. spinlock, or RW locks in terms of performance.

    Well, when you go for atomics, what you actually do is providing your own implementation of a spinlock. At the risk of invoking Mr.Burn's wrath I have to point out that there are some (admittedly rare) situations when providing a custom spinlock implementation may be, indeed, beneficial

    Anton Bassov

  • Mark_RoddyMark_Roddy Member - All Emails Posts: 4,374
    via Email
    (physical memory)/(sizeof pointer)

    Mark Roddy
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Writing WDF Drivers 7 Dec 2020 LIVE ONLINE
Internals & Software Drivers 25 Jan 2021 LIVE ONLINE
Developing Minifilters 8 March 2021 LIVE ONLINE