Eric Hodel (drbrain) wrote,
Eric Hodel

  • Mood:


Pthreads are cool, as part of a homework problem I was to implement a monitor that would allow processes each with a unique priority to access a file concurrently so long as the sum of the priorities was less than n.

So I wrote it, tried again, rewrote it, etc. I probably had a solution in there somewhere, but didn't know it because it always ran the threads sequentially (due to some weirdness I'll explain later). Eventually I poked around on google and got a pthread monitor-like dummy implementation. I slapped that in, added the pieces I needed to protect the priority counter and ran it.

Unfortunately there is something odd about how the program reacted to being piped to a file or more. Whenever I did this it executed the threads sequentially, and more than one thread never executed in the monitor at once. When I used the console scrollback, I could see multiple threads executing in the monitor at once.

In all, my solution is fairly elegant. I pass in a function pointer that does the work in the monitor and gets called at the right time. This protects the programmer from their own mistakes and allows them to make a single call when attempting to do work.

Tomorrow I'll have to post a link to my solution.


  • (no subject)

    I dreamed I was in a grocery store with my mom reading Seattle Weekly from sometime late at night until 11AM. The Seattle Weekly had an article about…

  • Free Microwave! (and stuff)

    I have a convection oven microwave (this means you could bake a cake in a metal pan in it) I'd like to get rid of. If you or anyone you know would…

  • Tools!

    Today I used several of my tools. My new Collector Vehicle plate arrived, so I retired the 948-MPC plates to my closet and attached the new plate.…

  • Post a new comment


    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.