Programming :: Avoiding Deadlock With Multiple Locks / Resources
Jun 16, 2011
Thanks to a recommendation and extensive help at phpbuilder.com, I have a multithreaded PHP script running in the cloud which fetches images and stores them the cloud. It's fast and seems quite stable.However, I believe I'm faced with a situation where I need to introduce an additional lock to my code so I'm faced with the task of managing multiple locks while avoiding deadlock.I was wondering if anyone had experience managing multiple locks in a MT environment and could recommend specific functions and data structures. I've been reading up on resource management in MT code and understand a few things:
1) Any shared resource (global and static vars, memory, file descriptors, etc.) generally needs to be protected by some kind of mutex, lock, or other sync var.
2) There are certain necessary conditions for deadlock to occur.
3) You generally need a sequence or hierarchy of your resources so that all threads request them in the same order. This sequence must be the same and immutable for all participating threads, whether local or remote.
4) Recursion is a very common cause of deadlock, so a process should know what locks it has acquired previously in order to avoid blocking in the attempt to re-acquire those same locks again.
5) There are a variety of algorithms described such as the Banker's Algorithm, the Chandy/Misra solution, etc. to help avoid deadlock.
I'm hoping to come up with a technique for properly handling multiple locks/mutexes/sync vars that I can re-use in the future, but I'm still coming to grips with the algorithm descriptions and am unsure precisely what sorts of data structures or functions I'll need.
View 3 Replies
ADVERTISEMENT
May 12, 2011
The following two pieces of codes share printing to stdout with a POSIX semaphore /dev/shm/sem.abcd
sema1.c:
Code:
int j;
sem_t *sem = sem_open( "/abcd", O_CREAT, S_IRUSR|S_IWUSR, 1 );
j = 0;
while (j < 100) {
[Code].....
If started at the same time, the first will finish in about 10 seconds; the second 20 secs.
What I want to ask is, if the first program crashes at Checkpoint A, then B will never gets to continue, then normally how do programmers avoid this kind of deadlock due to crashes inside the critical section?
View 3 Replies
View Related
Jun 27, 2010
I have two modules A and B in the kernel which i am trying to hack by introducing a variable in A which is of type 'extern' (and using EXPORT_SYMBOL) and then calling it in B. Now the problem is how to introduce that variable in module A. Currently i have made a global variable and it works fine but global variable in kernel is a bad bad thing.
I tried having an 'extern' function in A which have that variable and calling that function in module B, but then again how would module A use my variable unless the variable is available outside the scope of that function and that again means a global variable.
View 3 Replies
View Related
May 9, 2011
I am going to write two or more programs that will take control of the same resources on Linux. What are the common methods/functions that can do locks/synchronizations in C?
View 1 Replies
View Related
Jul 12, 2010
I am starting a new job, and need to brush up on my expect scripting. does anyone know of any online resources, e.g. telnet sites that I can play about with?
View 4 Replies
View Related
Jan 28, 2011
Is it possible to for me directly RDP into my company's RDP server from my Linux OS, in same way I can RDP into it from my Windows OS on my work computer or home computer, which has the RDP setup settings you use to create the session?
Of course I can get into the work machine, and then the RDP session, but is there a way to go straight into it without using the Windows Desktop to click on RDP? Does Linux have an RDP program similar to the setup using on the Windows side, in terms of being able to configure the settings to get into an RDP directly?
View 2 Replies
View Related
Jul 18, 2011
Slackware is very stable and very geek-friendly. I happen to love it... Unfortunately, I've found it unsuitable for day-to-day stuff in recent years, because it doesn't have a whole lot of software in its repos - and installing stuff from source can quickly lead you into dependency.
But pkgsrc has a vast amount of software in it, and can run on Linux. So it could be a solution, right?
The problem with pkgsrc is that the dependency resolution doesn't recognize stuff installed through standard Slackware packages. If you try to compile Gnash with it for instance, it will drag in Firefox and waste a few hours compiling that, even if you already installed Firefox through pkgtools. So with a default setup, pkgsrc is suitable for building on a very minimal Slackware system, but not for extending a preexisting Slackware desktop with Xfce and Firefox and whatever.
Is there any way of changing this, so that pkgsrc registers preinstalled binaries as providing whatever dependency? Or is that not possible? If not, is there any other system that could provide dependency resolution for compiling stuff?
View 11 Replies
View Related
May 7, 2010
[using Ubuntu 10.04 - Gnome] I know this is probably a dumb question, but after few years of not using linux i'm back to it and trying to catch up what i already forgot... i'm trying to make a shell script were when all the commands end or when i interrupt it (using ctrl+c) it wont close my terminal window.
i made a test scrip like this:
#!/bin/sh
echo hi there
and created a launcher by right clicking create launcher, selected console application, naming it and putting in the command field: sh "<path to file>/test.sh". (without sh at start it wont work)
so how can i avoid shell window closing after running/terminating the script? and is there any way i can do this by doing something like right click>add new link... i think that in kde it works like that...
View 8 Replies
View Related
Apr 24, 2010
I'd like to know if there's a way to disable system suspension during mplayer playback, I'm using kde 4.4.2 by AlienBob on my slackware64-current, and powerdevil as the power manager. In powerdevil I've setup the performance profile to suspend the system after 30 minutes with no user interaction, and the presentation profile is setup not to use suspension at all, but I always forget to switch the profile before playing some long video on mplayer and the system goes down after 30 minutes of playback.
Does someone knows a way, a hidden mplayer setting (powerdevil setting would be ok too) that lets me disable suspension only when mplayer is working and nobody is using the system for more than 30 minutes??
View 2 Replies
View Related
May 29, 2011
I have recently purchase some audio equipment and am wanting to get the most out of it. From what I've read, an OS/media player will tend to "resample" audio frequencies at the software/soundcard level before sending it, and from what I gather, that isn't a perfect 1-to-1 copy of my audio to my speaker. My equipment:
Ubuntu: 11.04 x64
Mobo (integrated sound): ASUS P5QL-CM - S/PDIF out on Intel G45 chipset / VT1708B, 8-Channel High-Definition Audio CODEC
AV receiver: Onkyo HT-R380 (PDF manual)
Speakers: Stereo (connected to 'A' ouput on AVR) - Acoustic Research Red Box II (circa early 90s)
I have the ASUS S/PDIF 'addon' and I have Ubuntu set to send audio through that. I think "bit streaming" is what I am after but I am at a loss as to how to make it happen.
View 1 Replies
View Related
Jun 5, 2011
Few days back when I tried to install java application using software manager, I got the message that my software manager has broken down. Since then I was not able to install any of the applications either through terminal or the software manager. Luckily, I got another fresh copy of Linux Mint 10(Julia) installed on my laptop. Looking for some efficient method of installing the required applications(java and its associated applications) so that I do not face such problems again in the future.
View 5 Replies
View Related
Jan 4, 2010
I am connecting servers using NFS4 the shared directories are on servers running Debian 4 while the one who read from them is Debian 5.0.3. The problem is one of these shared servers suddenly stop responding and you cannot list it from Debian 5 server, also df hang, and the web application that is using it does not respond to requests that use this shared directory since it is blocked. Then the load on the server start to increase until the server cannot respond (over 90). I have found many entries in the syslog that refer to this like:
ma25555 kernel: [1200285.732919] nfs: server 10.xxx.xxx.xxx not responding, still trying
Dec 31 08:16:33 ma25555 kernel: [1200289.815378] INFO: task java:9702 blocked for more than 120 seconds.
Dec 31 08:16:33 ma25555 kernel: [1200289.835249] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
code....
I have tried the connection between the 2 servers using ping for one day and all are OK (zero lost)
There are 3 other servers that are running Debian 4 and are working fine.
View 1 Replies
View Related
Jan 9, 2011
I have my desktop with following hardware:
1. MB: ASUS P5QL SE/EPU
2. RAM: 2 x 2GB Corsair PC2-8500 (1066 MGhz)
3. CPU: Intel Dual-Core E6500
4. GPU: nVidia GeForce 9400 GT with binary driver
5. Net: D-Link DWA-520 with madwifi driver
This machine is running for more than two years without any problem, but during the last 2 or 3 months I get deadlock hangs once or twice a week. This machine runs Slackware-current 32 bit with custom compiled vanilla kernel with two additional patches - BFS and TuxOnIce. Deadlocks usually occur when there is no user activity - only rtorrent is running and two KDE4 sessions is open (with firefox, okular, claws-mail, goldendict, virtualbox and other memory consuming apps).
Here is an excerpt from my syslog:
Quote:
I just would like to get a clue - what should I replace first - a memory or a CPU? The price is almost the same - around hundred of bucks. I tried to run memtest86 3.5a and got 1983 memory errors, but I had several problems with false positive errors with earlier versions of memtest86 and I don't trust it on 100%. My idea is to update BIOS firmware, update to the new kernel (I'm waiting for 2.6.37) and only then replace a RAM.
View 11 Replies
View Related
Jun 24, 2009
I've browsed the internet, but haven't found a satisfying answer. Hope this forum can help me in the right direction.I'm exploring the possibilities of creating a program that manipulates (writes to) two different video cards.I program in C and hope to avoid high level libraries like Xlib to keep the mem footprint as low and the performance as high as possible. Windowing is not important no desktop environment will be used. Be able to write two pixels (one to each screen) to would do.
How would I go about?To give an idea of the solution I'm looking for:One screen will show thumbnails of images on the hard drive. Clicking an thumbnail on display A will show the selection full screen on display B. On a laptop; preferably thumbnails on the laptop screen and the selected image on the external monitor.Is this possible with just low-level libs or do I need X or some third-party software to make life easy?
View 14 Replies
View Related
May 28, 2010
I am using Ubuntu 10.04 64 bit on my vaio VGN-NS325j. Using Eclipse as my IDE. But i have a big problem ; while i am debugging my app. It is locking my interface. No more responses for my mouse clicks or keyboard.. Machine is still working.. If there is an application running on background it is continuing what it is job is.But i could interact with anything. It is just happening during debugging.. Otherwise it is fine.In addition my app is running on Jboss 4.2.2 if it helps.
View 1 Replies
View Related
Apr 17, 2009
I use a mencoder line to convert .avi to .mpg (dvd player compatible), it works well but i can only do one file at the time. It requires giving the input and output directories and the files name. I tried using (*.avi *.mpg in the command) on the directory but it just add up all the .avi and convert them into one huge .mpg. My goal is to have a script that would convert all the .avi files from a directory to the same amount of .mpg and also keep the naming of those files. Here is what i work with on single files:
Code:
mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd -vf scale=720:480,harddup
-srate 48000 -af lavcresample=48000
-lavcopts
[code]....
View 3 Replies
View Related
Apr 21, 2010
(i) I usually make multiple dir using -p optionex: mkdir -p dicttest/audrep/tdriver/testNow after creating this dir's i stay in current dir instead i want to go directly to test dir how can i acheive this.(ii) When i execute which command as followswhich testerm i will get the location of testterm now i want to open this filewhen i did in this wayhich testterm | vi The file dosent get opened how can i acheive this ?ex:
linuxx86:110$ which testterm
/view/rdl110_linuxx86/vobs_usrrdl/sc/testterm
linuxx86:110$ which testterm| vi
[code]....
View 3 Replies
View Related
Nov 12, 2010
I feel kind of embarrassed posting here, but this is technically a scripting sub-forum. Here is the problem. I have a folder with various files which include .txt files as well
How can i redirect same content to each of the .txt files in the folder?
I have tried
Code: $ echo "hello" > *.txt
-bash: !": event not found Code: also cat ~/otherdir/test.txt > *.txt
-bash: *.txt: ambiguous redirect Can anyone help me with this?Ok i solved it
Code: #! /bin/bash
for file in *.txt
do
echo "Text that needs to be written" > $file
done
View 2 Replies
View Related
Feb 23, 2010
I have a folder with only 24 files named <number>.dat (i.e. 4.dat, 6.dat and so on) where <number> is between 0 and 256. Each file has just two columns of data and nothing else.
I'm trying to combine all the second columns ($2) together. I've been fiddling around with getline and so far have
awk '{ getline ln < "6.dat" ; print ln" "$2 }' 4.dat
which takes file 4.dat and adds $2 from 6.dat, but I want a single command to take each $2 from every file and add them to (for example) 4.dat (having $1 from 4.dat is no problem). A command that takes every file in the folder and grabs $2 and places them in a common file would be ideal. Frankly I can work around if you combine both columns from every file.
View 5 Replies
View Related
Jan 30, 2010
I'm trying to write a .sh script that allows me to run multiple other .sh scripts at once.
My problem occurs within a Variable:
I have set
S1 to S7 to be the name of the .sh
A="7"
B="S$A"
C="$S$A" <- and this is where my problem is
I want C to be the content of S7 till S1 but if I run this line it will of course look for the content of S and link it with the content of A.
How can I correct this?
Edit:
WHERE="/home/X/Y/"
SH=".sh";
A="7";
B="S$A";
C="$B";
[Code].....
View 6 Replies
View Related
May 5, 2009
It is possible to run multiple instances of a jar executable. Is it possible that only a single instance of the jar runs? Wrappers like JSmooth or Launch4J can be made to run as a single instance. But since there are no such wrappers for linux, I need a way to restrict the jar to a single instance. How to embed the jar file into an executable such it runs a single instance?
View 14 Replies
View Related
Dec 30, 2010
I want grep multiple files:
let abc.1.abc.2,abc.3,abc.4
I use grep <pattern> abc.* to read the files. But here grep read files in the order of 1,2,3,4 . I want to to grep the files in reverse order like 1st the abc.4 file will be read and abc.1 file will be last.
Is this possible ?
View 3 Replies
View Related
Apr 22, 2011
I have prepared a script which will login to each server and search for a keyword.
I want output on same machine from where m running script.
When i try to run command on any machine.. It works well.
w=$(grep -irH "keyword.com" /home/*/public_html/*);if [ $? -eq 0 ];then echo -e "
$HOSTNAME";echo $(grep -irH "keyword.com" /home/*/public_html/* | cut -d: -f1 | uniq | awk '{for (i=1;i<=NF;i++) printf "%s
",$i}');fi
[Code]....
View 9 Replies
View Related
Nov 3, 2010
I have the following header file in /usr/include/test.h:
Code:
#ifndef TEST_H
#define TEST_H
const int test_version = 1;
#endif
[Code].....
View 3 Replies
View Related
Jan 12, 2011
how i could compile for example: a tutorial file of cantera open source files. when i do :g++ example.cpp -o examplei get huge errors such as the header files are not here,...please tell me how i could compile it. ofcourse i have configured the full opensources and i see in /usr/local/cantera/binthat the files are there but i still can not compile and execute any cpp file.
View 2 Replies
View Related
Aug 3, 2010
I am trying to implement a corba program (client) to retrieve customerinformation from the server. Since the server allow to login once andperform your operations until the lifetime experies, i want the client to use already login connection to perform the retrieve function withoutlogin in to the server for every request.Suppose retrieve has three functions, logon(), perform() and logoff()Pseudo code;Quote:
1. User runs a client application
./retrieve <URI> <customerID>
2. if the client program has already login, donot login, go to 4
[code]....
View 3 Replies
View Related
Nov 26, 2010
Code:
void* thread(void* arg)
{
[code]....
View 5 Replies
View Related
Aug 3, 2010
For example I want my Qt Creator app to have multiple custom dialogs. How do I manage them? Also, what if I want to replace all the widgets in a window with new ones, how do I manage that in Qt Designer?
View 4 Replies
View Related
Dec 4, 2010
I want to be able to use multiple options at the same time and some of those options will require an argument and some will not.
Here is my bash script:
#!/bin/bash
while getopts ":a:bc:de:fg:" opt ; do
case $opt in
a)
[Code]....
If I only use option -a with no arguments, the script works...
View 1 Replies
View Related
Jun 28, 2009
i need a script that will give as much system info such as CPU usage, partition info, mem usage, etc.. from multiple OS's, FreeBSD, AIX, HP-UX. I only know SCO unix and dont know the commands on the other OS's.
View 2 Replies
View Related