Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
970c6b37
Commit
970c6b37
authored
Dec 03, 2008
by
Michael Widenius
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add missing file: Testing of mutex-wrong-usage-detector
parent
98a8592c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
162 additions
and
0 deletions
+162
-0
mysys/test_thr_mutex.c
mysys/test_thr_mutex.c
+162
-0
No files found.
mysys/test_thr_mutex.c
0 → 100644
View file @
970c6b37
/* Copyright (C) 2008 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* Testing of deadlock detector */
#include <my_global.h>
#include <mysys_priv.h>
int
main
(
int
argc
__attribute__
((
unused
)),
char
**
argv
)
{
pthread_mutex_t
LOCK_A
,
LOCK_B
,
LOCK_C
,
LOCK_D
,
LOCK_E
,
LOCK_F
,
LOCK_G
;
pthread_mutex_t
LOCK_H
,
LOCK_I
;
MY_INIT
(
argv
[
0
]);
DBUG_ENTER
(
"main"
);
DBUG_PUSH
(
"d:t:O,/tmp/trace"
);
printf
(
"This program is testing the mutex deadlock detection.
\n
"
"It should print out different failures of wrong mutex usage"
"on stderr
\n\n
"
);
safe_mutex_deadlock_detector
=
1
;
pthread_mutex_init
(
&
LOCK_A
,
MY_MUTEX_INIT_FAST
);
pthread_mutex_init
(
&
LOCK_B
,
MY_MUTEX_INIT_FAST
);
pthread_mutex_init
(
&
LOCK_C
,
MY_MUTEX_INIT_FAST
);
pthread_mutex_init
(
&
LOCK_D
,
MY_MUTEX_INIT_FAST
);
pthread_mutex_init
(
&
LOCK_E
,
MY_MUTEX_INIT_FAST
);
pthread_mutex_init
(
&
LOCK_F
,
MY_MUTEX_INIT_FAST
);
pthread_mutex_init
(
&
LOCK_G
,
MY_MUTEX_INIT_FAST
);
pthread_mutex_init
(
&
LOCK_H
,
MY_MUTEX_INIT_FAST
);
pthread_mutex_init
(
&
LOCK_I
,
MY_MUTEX_INIT_FAST
);
printf
(
"Testing A->B and B->A
\n
"
);
fflush
(
stdout
);
pthread_mutex_lock
(
&
LOCK_A
);
pthread_mutex_lock
(
&
LOCK_B
);
pthread_mutex_unlock
(
&
LOCK_A
);
pthread_mutex_unlock
(
&
LOCK_B
);
/* Test different (wrong) lock order */
pthread_mutex_lock
(
&
LOCK_B
);
pthread_mutex_lock
(
&
LOCK_A
);
/* Should give warning */
pthread_mutex_unlock
(
&
LOCK_A
);
pthread_mutex_unlock
(
&
LOCK_B
);
/* Check that we don't get another warning for same lock */
printf
(
"Testing A->B and B->A again (should not give a warning)
\n
"
);
pthread_mutex_lock
(
&
LOCK_B
);
pthread_mutex_lock
(
&
LOCK_A
);
pthread_mutex_unlock
(
&
LOCK_A
);
pthread_mutex_unlock
(
&
LOCK_B
);
/*
Test of ring with many mutex
We also unlock mutex in different orders to get the unlock code properly
tested.
*/
printf
(
"Testing A->C and C->D and D->A
\n
"
);
pthread_mutex_lock
(
&
LOCK_A
);
pthread_mutex_lock
(
&
LOCK_C
);
pthread_mutex_unlock
(
&
LOCK_A
);
pthread_mutex_unlock
(
&
LOCK_C
);
pthread_mutex_lock
(
&
LOCK_C
);
pthread_mutex_lock
(
&
LOCK_D
);
pthread_mutex_unlock
(
&
LOCK_D
);
pthread_mutex_unlock
(
&
LOCK_C
);
pthread_mutex_lock
(
&
LOCK_D
);
pthread_mutex_lock
(
&
LOCK_A
);
/* Should give warning */
pthread_mutex_unlock
(
&
LOCK_A
);
pthread_mutex_unlock
(
&
LOCK_D
);
printf
(
"Testing E -> F ; H -> I ; F -> H ; H -> I -> E
\n
"
);
fflush
(
stdout
);
pthread_mutex_lock
(
&
LOCK_E
);
pthread_mutex_lock
(
&
LOCK_F
);
pthread_mutex_unlock
(
&
LOCK_E
);
pthread_mutex_unlock
(
&
LOCK_F
);
pthread_mutex_lock
(
&
LOCK_H
);
pthread_mutex_lock
(
&
LOCK_I
);
pthread_mutex_unlock
(
&
LOCK_I
);
pthread_mutex_unlock
(
&
LOCK_H
);
pthread_mutex_lock
(
&
LOCK_F
);
pthread_mutex_lock
(
&
LOCK_H
);
pthread_mutex_unlock
(
&
LOCK_H
);
pthread_mutex_unlock
(
&
LOCK_F
);
pthread_mutex_lock
(
&
LOCK_H
);
pthread_mutex_lock
(
&
LOCK_I
);
pthread_mutex_lock
(
&
LOCK_E
);
/* Should give warning */
pthread_mutex_unlock
(
&
LOCK_E
);
pthread_mutex_unlock
(
&
LOCK_I
);
pthread_mutex_unlock
(
&
LOCK_H
);
printf
(
"
\n
Following shouldn't give any warnings
\n
"
);
printf
(
"Testing A->B and B->A without deadlock detection
\n
"
);
fflush
(
stdout
);
/* Reinitialize mutex to get rid of old wrong usage markers */
pthread_mutex_destroy
(
&
LOCK_A
);
pthread_mutex_destroy
(
&
LOCK_B
);
pthread_mutex_init
(
&
LOCK_A
,
MY_MUTEX_INIT_FAST
);
pthread_mutex_init
(
&
LOCK_B
,
MY_MUTEX_INIT_FAST
);
/* Start testing */
my_pthread_mutex_lock
(
&
LOCK_A
,
MYF
(
MYF_NO_DEADLOCK_DETECTION
));
pthread_mutex_lock
(
&
LOCK_B
);
pthread_mutex_unlock
(
&
LOCK_A
);
pthread_mutex_unlock
(
&
LOCK_B
);
pthread_mutex_lock
(
&
LOCK_A
);
my_pthread_mutex_lock
(
&
LOCK_B
,
MYF
(
MYF_NO_DEADLOCK_DETECTION
));
pthread_mutex_unlock
(
&
LOCK_A
);
pthread_mutex_unlock
(
&
LOCK_B
);
printf
(
"Testing A -> C ; B -> C ; A->B
\n
"
);
fflush
(
stdout
);
pthread_mutex_lock
(
&
LOCK_A
);
pthread_mutex_lock
(
&
LOCK_C
);
pthread_mutex_unlock
(
&
LOCK_C
);
pthread_mutex_unlock
(
&
LOCK_A
);
pthread_mutex_lock
(
&
LOCK_B
);
pthread_mutex_lock
(
&
LOCK_C
);
pthread_mutex_unlock
(
&
LOCK_C
);
pthread_mutex_unlock
(
&
LOCK_B
);
pthread_mutex_lock
(
&
LOCK_A
);
pthread_mutex_lock
(
&
LOCK_B
);
pthread_mutex_unlock
(
&
LOCK_B
);
pthread_mutex_unlock
(
&
LOCK_A
);
/* Cleanup */
pthread_mutex_destroy
(
&
LOCK_A
);
pthread_mutex_destroy
(
&
LOCK_B
);
pthread_mutex_destroy
(
&
LOCK_C
);
pthread_mutex_destroy
(
&
LOCK_D
);
pthread_mutex_destroy
(
&
LOCK_E
);
pthread_mutex_destroy
(
&
LOCK_F
);
pthread_mutex_destroy
(
&
LOCK_G
);
pthread_mutex_destroy
(
&
LOCK_H
);
pthread_mutex_destroy
(
&
LOCK_I
);
my_end
(
MY_DONT_FREE_DBUG
);
exit
(
0
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment