From: 谢纲 <xiegang112@gmail.com>
To: linux-kernel@vger.kernel.org
Subject: new implementation of mutex
Date: Mon, 1 Jun 2009 14:49:09 +0800 [thread overview]
Message-ID: <d364733c0905312349m6b5c8664h6cc7701a576c6b7d@mail.gmail.com> (raw)
There is new implementaion in newer kernel (my kernel version is
2.6.27). Compared to the old implementaion which uses binary
semaphore, there are some new features:
- 'struct mutex' semantics are well-defined and are enforced if
CONFIG_DEBUG_MUTEXES is turned on. Semaphores on the other hand have
virtually no debugging code or instrumentation. The mutex subsystem
checks and enforces the following rules:
* - only one task can hold the mutex at a time
* - only the owner can unlock the mutex
* - multiple unlocks are not permitted
* - recursive locking is not permitted
* - a mutex object must be initialized via the API
* - a mutex object must not be initialized via memset or copying
* - task may not exit with mutex held
* - memory areas where held locks reside must not be freed
* - held mutexes must not be reinitialized
* - mutexes may not be used in hardware or software interrupt
* contexts such as tasklets and timers
But in my test, I try to lock mutex in one thread, and unlock it in
the other thread. There is nothing wrong happens. It works just like
semaphore. I have had CONFIG_DEBUG_MUTEXES turned on.
The two threads are mostly like this:
struct mutex mutex;
static int mysthread1(void * data){
int i;
i= 5;
while(i -- > 0){
mutex_lock(&mutex);
printk("this is thread1\n");
msleep(5000);
}
return 0;
}
static int mysthread2(void * data){
int i;
i= 5;
while(i -- > 0){
printk("this is thread2\n");
msleep(5000);
mutex_lock(&mutex);
}
return 0;
}
I debug it and find the debug_locks = 0. Is this why there is no
warning message and how turn it on? (I also had CONFIG_LOCKDEP_SUPPORT
on.)
--
Xie Gang
next reply other threads:[~2009-06-01 6:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-01 6:49 谢纲 [this message]
2009-06-01 7:27 ` Ming Lei
2009-06-01 8:57 ` 谢纲
[not found] ` <7b6bb4a50906010206k412d6178lbf56856b2b8cce9c@mail.gmail.com>
2009-06-01 9:28 ` 谢纲
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d364733c0905312349m6b5c8664h6cc7701a576c6b7d@mail.gmail.com \
--to=xiegang112@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®