Implementing "critical sections" using recursive mutex locks
Greetings.
I have chosen pthread mutexes for implementing critical sections in my ported Windows code. As you probably all know, mutexes do not by default support recursive locking and will deadlock if attempted. With Solaris 7 came support for recursive locking through the PTHREAD_MUTEX_RECURSIVE type of mutex. The problem I have encountered when using these recursive mutexes doesn't even involve recursive locking, yet only manifests itself when using the recursive type.
To pin-point the problem, I have written a very simple application that creates 10 threads and pauses (via sleep()) for an amount of time sufficient for all threads to complete. In each thread, a global mutex (recursive type) is locked and then immediately unlocked, with status going to stdout via printf. There is no problem with this simple application and all threads run to completion after each gets the mutex lock in succession. To really test the mutex however, I simulated a pre-empted or otherwise blocked thread via a call to sched_yield() after locking the mutex and before unlocking it. In this version of the application, only the first thread to acquire the mutex lock completes (after successfully locking and unlocking the mutex), and all other threads hang waiting to acquire the mutex lock.
Any insight on this problem or suspected problems with the code I described would be GREATLY appreciated! I would be happy to send the source to this simple application to anyone interested in observing it's behavior.
Regards and thanks in advance.
Chad Attermann
telic.net
Solaris 7 is shipped broken for recursive mutexes... You can fix it by using patch 106980-13 and everything it depends on...
Good luck!
Similar Messages
-
Should I be able to see a priority change using a mutex lock ?
If I have a program which uses a mutex lock in solaris 9 which is set up to protect/priority ceiling of 5 and kick it off using priocntl with a priority of 11 and RT, I can look at top and see that it has priority 111. So my process is running real time. I then use a second xterm and wait till the program hits the lock portion of the code. If I do a priocntl -d pid, it is still priority 11. I know it is in the lock because there is a printf and a sleep of 20 seconds. Should I be able to see the priority go to 5? How can I prove the priority inheritance off the mutex lock is working in a test program, so that I know I am using it correctly? Thanks for any insight.
I also tried it with a priority ceiling of 50, figured out that RT priorities worked the reverse of regular priority, the higher the priority number, the higher the priority. I still however am not able to prove the priority inheritance occured. Anybody got any thoughts on how to prove it is working properly.
-
Is there any known issue about mutex lock used in JNI on Solaris 10?
Dear Oracle,
I'm facing a strange behavior when running a JNI application that use the mutex lock. The application hanged after running for a while on one of our Solaris 10 machines. After investigating the stack trace of the application, it shows that one of all the application's threads that access the JNI hold the mutex lock forever, and that cause the other threads cannot access the JNI. The same application works fine on other Solaris 10 machines.
The mutex function I used as show below:
mutex_lock(&mutex)
The application hanged at this line:
0xff2cc940 ___lwp_mutex_timedlock + 0x8
The Kernel version is SunOS 5.10 Generic_142900-14
Since this issue occurrs on only one Solaris 10 machine in our environment, we are wondering if there is any known issue regarding the mutex lock used in JNI on Solaris 10. We tried to search the Internet and the Java Bug database but found nothing related to this issue.
Best regards,
Krit K.876587 wrote:
... and that cause the other threads cannot access the JNI. The same application works fine on other Solaris 10 machines.
Different environments mean just that. So something could be causing it outside java.
Additionally if anything at all is different in the execution data, such as even a name having a different size, then it would change the execution path.
Which would cause a problem in the JNI code to manifest itself on only one box. Probably isn't a pointer bug but all sorts of odd behavior can result from that. -
Should I be able to see a priority change using a mutex priority ceiling
If I have a program which uses a mutex lock in solaris 9 which is set up to protect/priority ceiling of 5 and kick it off using priocntl with a priority of 11 and RT, I can look at top and see that it has priority 111. So my process is running real time. I then use a second xterm and wait till the program hits the lock portion of the code. If I do a priocntl -d pid, it is still priority 11. I know it is in the lock because there is a printf and a sleep of 20 seconds. Should I be able to see the priority go to 5? How can I prove the priority inheritance off the mutex lock is working in a test program? Thanks for any insight.
I also tried it with a priority ceiling of 50, figured out that RT priorities worked the reverse of regular priority, the higher the priority number, the higher the priority. I still however am not able to prove the priority inheritance occured. Anybody got any thoughts on how to prove it is working properly.
-
How to implement a "mutex" lock
Hi there, I'm in a need of creating something like a mutex mechanism, not related to a table.
Is it possible or do I have to fill in any dummy table ?
Cheers,
BartHi,
The status monitor for the integrated ITS (transaction SITSPMON) is used to display the current status of the integrated ITS functionality in the application server. You can display and change the currently set parameters. You can get information on the memory load, on the content of the ITS caches, on set locks and on activated features.
Functions
The different pieces of information displayed on the screen are sorted by categories, which you can view using the respective tabstrip. Currently, the following display screens are available:
· Parameters
· Memory Statistics
· Template and MIME Cache
· Mutex Locks
· HTML Template Directory
· Feature List
Mutex Locks
Mutex Locks (Mutual Exclusions) prevent competing access to resources. The integrated ITS function uses mutex locks for the HTML template cache, which exists only once for all work processes, to prevent the situation that a work process stores a new HTML template version in the HTML template cache while another work process processes an HTML template.
Apart from this, mutex locks are used for
· Memory statistics
· Individual HTML template cache entries
· HTML Template Directory
Try exploring how this functionality have been done in transaction SITSPMON.
Regards,
Harish -
Critical section with Sql*Load
Hi,
I need to prevent multiple instances of a batch job from running at the same time. This is easy when the batch job is pure PL/SQL. A critical section implemented with DBMS_LOCK does the job just well.
But now I have a batch job which first uploads a file using Sql*Load, and only later calls Sql*Plus and PL/SQL.
How do I prevent multiple instances of my Sql*Load from running in parallel ? (i.e. writing into the same table).
I've heard about restricting the number of concurrent sessions in the login profile. Trouble is, I have a dozen different "types" of batch jobs, and we don't want to have a dozen different logins. Batches of different types are allowed to run in parallel, and this is even desirable.
AndrewSince sqlldr is essentially an O/S command, you will need to do the locking at the O/S level. Depending on how you call the batch jobs, you have two choices.
If the controlling script and/or the loader control file for each batch have a consistent name, then you can do something like:
#!/usr/bin/ksh
me=$$
while [ $me -ne 0 ]
do
run=`ps -ef |grep <<script_or_control_file_name>> |grep -v grep |grep -v $me`
if [ "$run" = "" ]; then
run sqlldr and
rest of batch commands
break
else
sleep or exit or whatever
fi
done
-- Any post processing requiredWe have situations where the controlling shell script, and the loader control file are automatically created by a master control program. Since the file names differ for every run, we use a structure like this:
#!/usr/bin/ksh
flagfile=batch1.flg
while [ $flagfile = $flagfile ]
do
if [ ! -f $flagfile ]; then
touch $flagfile
run sqlldr and
rest of batch commands
if [ successful ] ; then
rm $flagfile
fi
break
else
sleep or exit or whatever
fi
done
-- Any post processing requiredHTH
John -
Mutex locking issue on Solaris 10
We are having a problem with mutex locking.
On one scenario we are running our application
On a v245 running Solaris 10 6/06 update 2 patch 118833-24
On our 5120 we are running Solaris 10 8/07 update 4patch 137111-05.
Our application creates several thousand simultaneous mutex inits (pthread_mutex_init). Approx 12 are locked at any one time. Our problem is after several min the application fails because the mutex destroy does not appear to destroy the mutex. This is true only on our 5120 but not on our v245. As a result our application runs fine on the v245 but fails quickly on the 5120.
Do you have any knowledge of why this might be happening?
Any help you can provide in this will be greatly appreciated.
If this is not the right group to post this messages please let me know.
Thanks!How many threads do you have performing these mutex operations? The 5120 probably runs a lot more concurrent threads than the v245 does, so it's likely you're running into a race condition that's only apparent when the number of concurrent threads is large enough.
What kind of mutexes are they? Recursive, process-shared, "normal"? Where are they located? Dynamically-allocated heap memory, local stack variables, mmap()'d memory? If they're recursive or "normal" mutexes in heap memory, you've most likely got a race condition in your application, because the source code at opensolaris.org for pthread_mutex_destroy() is pretty much nothing but "memset( &mutex, 0, sizeof( mutex ) )" for normal mutexes. It's hard to imagine how that could fail.
You can use the race-condition tools that are part of Sun Studio 12 or another memory-checking application such as Purify to find out where your error may be. Given the timing issues apparently involved, those are probably your best options. The overhead of tools such as watchmalloc or even the run-time memory checker in Sun Studio may be too much and mask your timing issues. Assuming that's what the root cause of your problem is.
I didn't look at what's involved in destroying a process-shared mutex, though. That's a lot more complicated.
On edit: How do you know that pthread_mutex_destroy() is not destroying the mutex?
Edited by: AndrewHenle on Jun 16, 2009 3:46 PM -
Multi processor Solaris 2.6 and mutex locks
hi,
is anyone aware of any documented issues with Solaris 2.6 running
on dual-SPARC processors (multi-processor environment) where the
programs using "mutex locks" (multi-threaded applications), require
some special handling, in terms of compiling and linking, to some
special libraries.
as far as i remember, in some OS book, maybe Peterson's, it was said
that the mechanism for implementing mutex-locks on multi-processor
systems is to use low-level spin-locks. this brings down performance
on a single-processor system, making the processor doing busy-wait,
but this happens to be the only way of mutex-locking in a multi-processor
system. if this is so, then where is such behaviour documented in case
of Solaris 2.6.
i have had problems with my applications crashing (rathing hanging up)
in a vfork() on such a system, but same application works fine, with
100% reproducability, on a single-processor system.
thanks for any inputs or suggestions and/or information.
regards,
banibrata duttaI am also facing similar problem. Application which written using Mulit-Threaded using Posix Mutexes. When i run on SINGLE processor manchine, i.e.
SunOS sund4 5.7 Generic_106541-11 sun4u sparc SUNW,Ultra-5_10
It works perfectly.
But when try to run on dual processor machine, i.e.
SunOS sund2 5.7 Generic_106541-11 sun4u sparc SUNW,Ultra-250
It is blocking in the one of mutexes.
Please inform us what is problem. Mr. B. Datta, you comes to know
any channel, please inform me also at [email protected]
Thanx & regards,
-venkat -
Critical Section Minus Synchronization
Without using synchronization would it be possible
to change these two classes so that each thread
takes it in turn to be in their criticall
sections i.e. one cannot take consecutive turns?
Thanks.
public class SharedVariables extends Object {
public int turn;
public boolean[] flag = new boolean[2];
public SharedVariables() {
flag[0] = false;
flag[1] = false;
// A thread running SectionedCode alternates between
// a critical section and the remainder.
public class SectionedCode implements Runnable {
int this_thread, other_thread;
SharedVariables s;
public SectionedCode( int tid, SharedVariables SV ) {
this_thread = tid;
other_thread = 1 - tid;
s = SV;
public void run() {
while ( true ) {
s.flag[this_thread] = true;
s.turn = other_thread;
while ( (s.flag[other_thread] == true) && (s.turn == other_thread) )
Thread.yield();
// Critical Section
System.out.printn("Thread "+this_thread+ "incritical section");
s.flag[this_thread] = false;
System.out.println("Thread " + this_thread + " in remainder");
}I am not sure if i understand the question BUT if i have understood you correctly, you should be reading up on the join feature in threads
-
How To Use Recursion In Forms?
I have the following table
Table name: Project_Details:
Coulmns:
Project_num Number(6) PK
Project_Title
Project_status
Parent_project_Number Number(6) FK (It’s a foreign key for the project
number in the same table)
Am using the Oracle Forms Builder to develop the following screen with the following data
Project Number: ……….
Parent Project Number: ……..
Childs Projects:
I have the following case that I don’t know how to implement:
Example:
The user create the following Project Numbers
Project number: 100 >>> Original or parent
New project 105 >>> Child of 100
New project 107 >>> Child of 105
New project 109 >>> Child of 107
So when the user re query 100 the Childs project filed should have 105,107 and 109 as a recursion of parents as shown below.
Screen Result:
Project Number: 100
Parent Project Number :
Childs Projects:
105
107
109
Another query with project number =107
Screen Result:
Project Number: 107
Parent Project Number : 105
Childs Projects:
105
100
If any body has any idea in how to implement this idea using oracle forms and SQL please help me. Its urgent..
Thanks in advanced..Hmmm, looks like you can't update a connect by prior view. That's a shame.
Anyway, here's what you need:
CREATE TABLE test
(child number
,parent number);
INSERT INTO test VALUES (1, null);
INSERT INTO test VALUES (2, 1);
INSERT INTO test VALUES (3, 1);
INSERT INTO test VALUES (4, 2);
INSERT INTO test VALUES (5, null);
INSERT INTO test VALUES (6, 5);
INSERT INTO test VALUES (7, 6);
INSERT INTO test VALUES (8, 5);
CREATE OR REPLACE VIEW test_hier_vw
AS
select lpad(' ',2*(level-1)) || to_char(child) hier
from test
start with parent is null
connect by prior child = parent;
SQL> select hier from test_hier_vw
2 /
HIER
1
2
4
3
5
6
7
8
8 rows selected. -
Please Help - Permutations using recursion..
Please some body help me in generating permutaions using recursion..exact guidelines are as follows..
Producing consecutive permutations.Need to develop a method that lists one by one all permutations of the numbers 1, 2, �, n (n is a positive integer).
(a) Recursive method . Given a verbal description of the algorithm listing all permutations one by one, you are supposed to develop a recursive method with the following header:
public static boolean nextPermutation(int[] array)The method receives an integer array parameter which is a permutation of integers 1, 2, �, n. If there is �next� permutation to the permutation represented by the array, then the method returns true and the array is changed so that it represents the �next� permutation. If there is no �next� permutation, the method returns false and does not change the array.
Here is a verbal description of the recursive algorithm you need to implement:
1. The first permutation is the permutation represented by the sequence (1, 2, �, n).
2. The last permutation is the permutation represented by the sequence (n, �, 2, 1).
3. If n a ,...,a 1 is an arbitrary permutation, then the �next� permutation is produced by
the following procedure:
(i) If the maximal element of the array (which is n) is not in the first position of the array, say i n = a , where i > 1, then just swap i a and i-1 a . This will give you the �next� permutation in this case.
(ii) If the maximal element of the array is in the first position, so 1 n = a , then to find
the �next� permutation to the permutation ( ,..., ) 1 n a a , first find the �next�
permutation to ( ,..., ) 2 n a a , and then add 1 a to the end of thus obtained array of (n-1) elements.
(iii) Consecutively applying this algorithm to permutations starting from (1, 2, �, n),you will eventually list all n! possible permutations. The last one will be (n, �, 2, 1).For example, below is the sequence of permutations for n = 3 .
Please help...i have trying this for long time
plesae help...i apreciate your time..and help..thank youpublic class Permu {
public static boolean nextPermutation(int a[]) {
return(permute(a, 0));
public static boolean permute(int v[], int start) {
int n = v.length;
if (start == (n - 1)) { //if its the end of the sequence genereated then print them
count++;
//print(v,n);
return false;
} else {
for (int i = start; i < n; i++) { //swap the start element with the ith element to get n first sequeces
int temp = v[start];
v[start] = v;
v[i] = temp;
permute(v, start + 1);
//of the n the first is kept constant the same is applied for the rest sequence
//int tmp = v[i];
v[i] = v[start];
v[start] = temp;
return true;
public static void main(String[] args) {
int v[] = {1, 2};//this is the array which should contain the items to be permuted
do{
for(int i=0;i<2;i++)
System.out.print(v[i]);
System.out.println();
}while(nextPermutation(v));
[i]Output:
123
123
123
123
123
This is exact code i am trying to run...pls someone help me out... -
Hello all,
I have the following situation:
- one thread (T1) is constantly reading samples from a NI USB 9229 in a local buffer and copying them an array A (44100Hz)
- another thread (T2) is waiting for a command and subsequently copying a batch of 44100 samples from A to a local array variable and doing some computation with them
- array A is protected in a critical section (T1 and T2 enter the critical section when working with A directly and leave it afterwards)
How "atomic" is the reading of samples from the device in my array A? I.e., is it guaranteed that the critical section protection on A means that by the time T2 accesses A, T1 has finished writing 44100 samples in it?
Or do I have to register with DAQmxRegisterEveryNSamplesEvent() a callback which 1) reads 44100 samples, 2) notifies T2 that the batch is complete and available?
Thank you in advance!
Message Edited by acgrama on 02-08-2010 08:30 AM
Solved!
Go to Solution.As far as I can understand the situation, the answer should be 'yes': the array is protected until you leave the critical section.
But could I suggest an alternative, perhaps simpler approach?
If you configure a thread safe queue of 44100 elements which discards old elements, with T1 that fills it on top, T2 can freely read from the queue without disturbing T1, having available the most recent set of data in any moment.
Proud to use LW/CVI from 3.1 on.
My contributions to the Developer Zone Community
If I have helped you, why not giving me a kudos? -
I tried to look for how to use adaptive mutexes as they are available on version 2.7 onwards. But in man pages I did not get enough hints. To my understanding, the default mutex behaviour is spin wait and not adaptive wait.
Can anyone give a pointer to this info or a piece of code using it. I want to use it in application program and which need not necessarily use ddi interface.
Also I want info about if these mutex locks can be created with "process robust" option.So do you mean I have a per-instance pollhead structure and I make the *phpp (4th argument to xxchpoll) point to the address of this pollhead structure so that once xxchpoll() returns, my local pollhead structure (for that instance of the driver) will be initialized ??
-
Explain how to implement prompt functionality using @variable
Hi all,
Anyone please explain how to implement prompt functionality using @variable.
We got some sql reports.Those reports have to be converted into BO free hand sql report.
Please provide any best practices for converting sql reports into BO free hand SQL.
Thanks & Regards,
James CharleHi
Please refer "@Variable" section in page number 601, in http://help.sap.com/businessobject/product_guides/boexir31SP3/en/xi31_sp3_designer_en.pdf
Regards
Ashwini -
How to extract the content of a section using VBA?
For example, I have an article like this:
Abstract
AbstractParagraph1
AbstractParagraph2
Body
BodyParagraph1
BodyParagraph2
Reference
ReferenceParagraph1
ReferenceParagraph2
Knowing that Abstract, Body and Reference are all headings, which means if I click the triangle button on the left of the heading (For example, Abstract), AbstractParagraph1 AbstractParagraph2 will shrink or expand. So my question is: how to retrieve the paragraph
in a specific section using VBA?Hi UW,
>> how to retrieve the paragraph in a specific section using VBA?
In my option, you could use the Section Object (Word) to get the section object, and then use the Section.Range Property (Word) to get the content of the special section. The links below might be useful to you.
# Section Object (Word)
https://msdn.microsoft.com/en-us/library/office/ff194295.aspx
# Section.Range Property (Word)
https://msdn.microsoft.com/en-us/library/office/ff836097.aspx
Best Regards,
Edward
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
Maybe you are looking for
-
IMac will not boot with iPod connected
Hello everyone I have a new iMac Core 2 Duo 17 inch 2.0 ghz and it seems to have a problem starting up when a 5th generation iPod is connected to the computer. When the computer is turned on with the iPod connected, the blank grey screen comes on, ye
-
Can anyone help me figure out how to get yahoo mail to open in safari? I tried but safari couldn't open it and said I had to go to settings-safari-private browsing- turn off, I tried to find the private browsing section but could not locate it please
-
Hi Oracle Team I have the Dell XPS 1530 for which I have installed the OEL, now some of my devices are not working as Sound Driver or Network Driver, please help me to get all the required drivers for Linux OS. ~ Ashish | 630 487 9486
-
Xmonad, xorg 1.9, and catalyst-test
Hi guys, I'm running xorg 1.9 and catalyst-test on my HP Envy 15 (which contains a Radeon Mobility 5830.) Almost everything works; nothing strange appears in /var/log/Xorg.log or glxinfo. It's clear that my hardware acceleration is fine because I'm
-
Turn off scroll pane component
have scroll pane component applied to an image within a movieclip timeline. after clicking to the frame with the scroll pane, every frame thereafter has the scroll pane image in the background.