login
Header Space

 
 

RE: thread scheduling at mutex unlock

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <avg@...>
Cc: <freebsd-stable@...>, <freebsd-threads@...>
Date: Thursday, May 15, 2008 - 6:37 pm

> David,
 

Yes. It demonstrates the classic example of mutex abuse. A mutex is not an appropriate synchronization mechanism when it's going to be held most of the time and released briefly.


I guess it comes down to what your test program is supposed to test. Threading primitives can always be made to look bad in toy test programs that don't even remotely reflect real-world use cases. No sane person optimizes for such toys.

The reason your program behaves the way it does is because the thread that holds the mutex relinquishes the CPU while it holds it. As such, it appears to be very nice and is its dynamic priority level rises. In a real-world case, the threads waiting for the mutex will have their priorities rise while the thread holding the mutex will use up its timeslice working.

This is simply not appropriate use of a mutex. It would be absolute foolishness to encumber the platform's default mutex implementation with any attempt to make such abuses do more what you happen to expect them to do.

In fact, the behavior I expect is the behavior seen. So the defect is in your unreasonable expectations. The scheduler's goal is to allow the running thread to make forward progress, and it does this perfectly.

DS


_______________________________________________
freebsd-threads@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-threads
To unsubscribe, send any mail to "freebsd-threads-unsubscribe@freebsd.org"
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: thread scheduling at mutex unlock, Andriy Gapon, (Thu May 15, 5:01 am)
RE: thread scheduling at mutex unlock, David Schwartz, (Thu May 15, 3:29 pm)
Re: thread scheduling at mutex unlock, Andriy Gapon, (Thu May 15, 4:56 pm)
RE: thread scheduling at mutex unlock, David Schwartz, (Thu May 15, 6:37 pm)
speck-geostationary