* new implementation of mutex
@ 2009-06-01 6:49 谢纲
2009-06-01 7:27 ` Ming Lei
[not found] ` <7b6bb4a50906010206k412d6178lbf56856b2b8cce9c@mail.gmail.com>
0 siblings, 2 replies; 4+ messages in thread
From: 谢纲 @ 2009-06-01 6:49 UTC (permalink / raw)
To: linux-kernel
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
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: new implementation of mutex
2009-06-01 6:49 new implementation of mutex 谢纲
@ 2009-06-01 7:27 ` Ming Lei
2009-06-01 8:57 ` 谢纲
[not found] ` <7b6bb4a50906010206k412d6178lbf56856b2b8cce9c@mail.gmail.com>
1 sibling, 1 reply; 4+ messages in thread
From: Ming Lei @ 2009-06-01 7:27 UTC (permalink / raw)
To: 谢纲; +Cc: linux-kernel
2009/6/1 谢纲 <xiegang112@gmail.com>:
> 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.)
Please confirm CONFIG_PROVE_LOCKING is enabled.
Thanks,
--
Lei Ming
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: new implementation of mutex
2009-06-01 7:27 ` Ming Lei
@ 2009-06-01 8:57 ` 谢纲
0 siblings, 0 replies; 4+ messages in thread
From: 谢纲 @ 2009-06-01 8:57 UTC (permalink / raw)
To: Ming Lei; +Cc: linux-kernel
2009/6/1 Ming Lei <tom.leiming@gmail.com>:
> 2009/6/1 谢纲 <xiegang112@gmail.com>:
>> 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.)
>
> Please confirm CONFIG_PROVE_LOCKING is enabled.
It still does not work. No warning is found. It still behaves as
binary semophore.
Thanks,
>
> Thanks,
> --
> Lei Ming
>
--
Xie Gang
^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <7b6bb4a50906010206k412d6178lbf56856b2b8cce9c@mail.gmail.com>]
* Re: new implementation of mutex
[not found] ` <7b6bb4a50906010206k412d6178lbf56856b2b8cce9c@mail.gmail.com>
@ 2009-06-01 9:28 ` 谢纲
0 siblings, 0 replies; 4+ messages in thread
From: 谢纲 @ 2009-06-01 9:28 UTC (permalink / raw)
To: Xiaotian Feng; +Cc: linux-kernel
On Mon, Jun 1, 2009 at 5:06 PM, Xiaotian Feng <xtfeng@gmail.com> wrote:
>
>
> On Mon, Jun 1, 2009 at 2:49 PM, 谢纲 <xiegang112@gmail.com> wrote:
>>
>> 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);
I typied wrong funcion. Actually, I unlock mutex with mutex_unlock here.
>
> unlock here?
yes.
>>
>> }
>> 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
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>> Please read the FAQ at http://www.tux.org/lkml/
>
>
--
Xie Gang
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-06-01 9:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-01 6:49 new implementation of mutex 谢纲
2009-06-01 7:27 ` Ming Lei
2009-06-01 8:57 ` 谢纲
[not found] ` <7b6bb4a50906010206k412d6178lbf56856b2b8cce9c@mail.gmail.com>
2009-06-01 9:28 ` 谢纲
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®