Programming :: Pthread And Mutex With Short Unlock Time?
Jun 15, 2010
I am wondering if pthread could make that a single thread keeps the "mutex" all the time if the time it remains unlocked is very small.
thread1
{
while (1)
{
lock; do_task(); unlock();
[code]...
I experiment the thread2 never getting access to the mutex and never printing the nice message. I would expect that once thread2 calls "lock", it would get the mutex as soon as thread1 calls unlock() but it does not seem to be the case. If I add a sleep of some microseconds (100) in thread1 after unlocking the mutex, it solves the problem.
Does anyone know if this behaviour is normal? Is there a way to configure my mutex so that thread2 receives it when unlocked?I use
pthread_mutexattr_settype(&att, PTHREAD_MUTEX_RECURSIVE_NP);
pthread_mutex_init(&handle, &att);
to create my mutex. I am running ubuntu 9.04
View 3 Replies
ADVERTISEMENT
Apr 15, 2010
I'm just wondering what the limits for time are. I have a program that always takes exactly 20 ms, so I assume this is the lowest it can measure, but I want to see if there's some sort of documentation of this.
View 3 Replies
View Related
Feb 15, 2010
locking mutex (phtread_t type) in a signal handler function (installed by function signal()) for Linux. It seems that if the mutex has been previously locked by another thread outside the signal handler function and then the signal handler function tries to lock it, the whole process hangs.
View 5 Replies
View Related
Apr 7, 2010
I am working on an issue in mishandling of mutex. A process was holding onto to a valid mutex for running, within this routine, it created a local mutex variable, copied the content of the valid mutex into this local mutex variable, freed the valid mutex, then used the address of the local mutex variable as the parameter to functions pthread_mutex_unlock() and pthread_mutex_destroy(). It was observed that CPU load 100% with scheduler staying in a loop. The program was halted. I try to seek an explanation to the relation between the CPU load and mutex mishandling in this scenario. I also hope some one will share the experience how this bug might manifest into problems on other platforms.
View 3 Replies
View Related
May 28, 2010
I am getting following assertion in my application:
pthread_mutex_lock.c:275: __pthread_mutex_lock: Assertion `(e) != 35 || (kind != PTHREAD_MUTEX_ERRORCHECK_NP && kind != PTHREAD_MUTEX_RECURSIVE_NP)' failed.
all my mutexes are of type PTHREAD_MUTEX_RECURSIVE and as per all the man pages/tutorials, EDEADLK error is to be returned for mutex of type PTHREAD_MUTEX_ERRORCHECK ONLY.I really should not be hitting this assertion.Would some kinda weird memory corruption be causing this? Or is there something more to it that I am not aware of.I am using linux kernel 2.6.2, glibc 2.5 on PPC.
View 8 Replies
View Related
Mar 2, 2011
If multiple threads operate on a single shared resource, we can lock it using pthread_mutex_lock. Uptill that it is fine, but why again pthread_cond_wait?
int shared=0; // global
.
.
// Thread 1
pthread_mutex_lock(&mutex);
shared=1;
pthread_mutex_unlock(&mutex);
When thread1 invokes the mutex lock, no other threads can access it in parallel. So why again and what for we use, pthread_cond_wait( ).
View 2 Replies
View Related
May 22, 2010
I wrote some code in c, using pthread (I configured the linker and compiler in eclipse IDE first).
Code: #include <pthread.h>
#include "starter.h"
#include "UI.h"
Page* MM;
[Code]....
View 6 Replies
View Related
Jan 1, 2011
I have faced a problem with my code (a small tcp server). After the thread returns, the memory not decreases, but when a new connection is made, memory not increases and the new connection initialize a new thread with a same thread id of the previous thread. When two connections are made at same time, two thread ids are created and when the respective threads returns the memory not decreases. The Valgrind indicates that not memory leak occurs, the pointers are released. Indeed, more memory are allocate when new thread id is created. i used gcc and debian.
[Code]....
View 1 Replies
View Related
Mar 12, 2011
I have created a pthread, and installed a signal handler inside that, same way as we do in main( ) function. The thread's signal handler is a separate function. Surprisingly, it is not working, that is the thread's signal handler is not able to catch signals. Here is the code:
Code: #include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
#include <signal.h>
typedef struct data
[Code]...
View 1 Replies
View Related
Apr 19, 2010
I have an application that has pretty large memory profile. The general program flow is as follows:
Code:
main:
do 10 times:
[code]....
View 9 Replies
View Related
Mar 10, 2011
im writing a cross-platform software (linux/solaris/mac/bsd) so i was wondering, how portable is pthread library? out of 10 linux distros, how many will have it by default? and does it exists on mac/solaris/bsd by default? or user will have to install it?
View 6 Replies
View Related
Dec 14, 2010
I want to suspend/resume a thread. The library I am using is pthread.h.I am also running my application on linux.Is there any function in pthread. let me suspend a thread temporary?I have read a document in which it was mentioned thatthread does not support suspend/resume
View 4 Replies
View Related
Aug 20, 2010
I'm trying to figure out how pthreads are mapped from the compiler to the Linux kernel. The pthread prototypes are found in a compiler header file (pthread.h), yet the kernel would be responsible for scheduling the threads. So, how does the compiler resolve the pthread symbols at compile time?
View 1 Replies
View Related
Jan 12, 2011
I am working on a large program in C to run on Puppy Linux. I have multiple pthreads running. I want to be able to set the pthread SCHED_POLICY and priority in my program but I want a user to be able to run the program without root privilege.
Using a sticky bit and root ownership gives the user too much power because they will be able to write and compile their own scripts. Is there a way to use 'sudo' when I set the thread parameters from my program or something like this?
View 1 Replies
View Related
Aug 11, 2010
I installed network-manager-vpnc, configured cisco vpn through NetworkManager. It works slow, but the bigger problem is that after minute or so the connection just freezes.Then I tried kvpnc. It works like it should from speed point of view. But it also hangs up after minute or two.Tried to change MTU of my wired connection to 1500 - no good.Tried to uncomment line in /etc/ppp/options "mru 542" - no good.
Created /var/run/vpnc because it was giving some error "can't open pidfile /var/run/vpnc/pid for writing".From logs everything seems fine except for "nm-dispatcher.action:Script '/etc/NetworkManager/dispatcher.d/01ifupdown' exited with error status 1." in last line. If I use kvpnc it gives no errors.SO, how do I debug this thing or does anyone knows something I don't in this case?
View 5 Replies
View Related
Nov 12, 2010
I have installed ubuntu 10.10 for a short time, now I meet a problem:I always leave for lunch and leave my computer without turning off. When I get back, it shows a window. after I input my password, I enter my system.Then It halts, the only thing what I can do is moving mouse. After halting for nearly one minute, it resumes to normal.I hope someone can tell me what happens.
View 2 Replies
View Related
Sep 4, 2010
I have to compute prime numbers with threads in C. So I choose the algorithm "Sieve of Eratosthenes" and I tried to create 2 threads, but I don't know how to optimize my computing function with threads I beg for help. This is my function:
[Code]...
but it seems like the both of the threads are calculating the same function twice? Is it possible to be optimized or not?
View 7 Replies
View Related
Feb 14, 2010
I think this might be related to the changes to using udev or DeviceKit. It started when I was running the beta versions of F12. Then it crept into Debian Sid. And my Arch Testing and Gentoo also suffer from the same.
What happens is that I'll be working along. Then when I press any key it is as if the SHIFT key is pressed. When I press CAPSLOCK, some of the keys react as they would normally. This never lasts for more than 5 minutes. And seems to happen infrequently. I say seems because there are the times I am at work and it could be that the same thing is happening only there is no one on the keyboard.
The reason I pick out udev/DeviceKit is that when it used to happen to F12 beta, the other distros had not yet made the move. So back then it was only a F12 issue. Now it is happening across the board. And only started recently.
View 3 Replies
View Related
Jun 10, 2010
I am backing up data from a remote server onto a local ntfs partition. It seems that the rm -rf and cp -a commands are taking a long time to complete in what should be short, incremental backups.Has anyone had similar problems when backing up to an ntfs partitionHere is my rsnapshot.conf:
Code:
#################################################
# rsnapshot.conf - rsnapshot configuration file #
[code]....
View 5 Replies
View Related
Mar 10, 2011
ubuntu 10.10 64bit my system clock keeps running late, and for some reason, I can't use NTP to synchronize it.If I try to use System -> Preferences -> Administration -> Time and date I can't unlock the popup (see attached screenshot) - I can click on the little yellow lock icon but when I do so, nothing happens.I tried "sudo ntpdate..." but i get the "the NTP socket is in use, exiting" error.
View 9 Replies
View Related
Apr 19, 2010
I'm building a simple(?) socket server using threads to serve up a few requests. The spec is such that I have to listen to three ports at once, so I decided to use pthread to create three separate threads that would wait for connections, then spawn new threads to handle them.
The problem is that when I do this, for some reason the program never enters the wait loop and instead terminates (All three threads did get created since the messages get printed properly.) It gets to the line which prints "???", but not the line after the accept() call.I don't see an open port when I check for one either so I'm 99% sure they're terminating.Basically I have a main() method which has three calls to pthread_create, which should result in three threads being run that all wait for connections (listenOnPort). After each thread creation I print some info to make sure it's actually being created.
By the way, when I just run listenOnPortwithout threading, the server appears to enter the loop correctly and seems to be waiting for requests. It's only when I run the functions as threads that the problem seems to happen.The source is attached below. Any help will be appreciated. Much of the code is borrowed from a website (I can't post it because I am new here.) You need not worry about the handler_ methods because those are just methods that are run by the threads themselves.
Also--the original source was in C and I changed it to C++. Should I just use C?
server.h Code: /*
* server.h
[code]....
View 1 Replies
View Related
Apr 13, 2010
This isn't a problem with the 2.6.26 kernel that I have been using, but it is with newer ones. I want to upgrade to a backports kernel, because there has been a REALLY long standing 2.6.26 bug with cpu frequency governors and suspending that is never going to get fixed.
Basically, with the 2.6.30 backports kernel, the hard drive spindown time is way too short. I'd like it to spin down after a minute or two of inactivity, but it is spinning down after only 5-10 seconds. Is there any way to fix this? edit: Now that I think about it, this is also a problem on another laptop that runs squeeze.
View 2 Replies
View Related
Jul 26, 2010
i have an application that launches several pthreads, i know that the default size used by Linux is 8Mb for each pthread. However i would like to optimize the total memory usage by my application by decreasing the default stack size of each pthread to the needed resources. My questions:
- Are there any rules to set the pthread stack size.
- How to compute the memory needed by each thread.
- Is the malloc call inside a thread counted from the stack size of the same pthread?
View 2 Replies
View Related
Apr 9, 2010
I updated Fedora 9 yesterday. I rebooted earlier and now the desktop starts for a very short time then disappears followed by a window opening and closing for a few goes. After this nothing! YUM does not work, neither does Firefox! A bug report informed me there was a Python problem but I can find no reference to this anywhere.
View 1 Replies
View Related
May 20, 2010
Has anyone got Ubuntu 10.04 working on their Dell Inspiron 1100? Most of the time, the screen goes black a short time after boot. Sometimes it goes black right after the splash screen, sometimes I get to log in and then it goes black a little later. Same results when trying to boot into "safe graphics" mode. Ubuntu 7.10 works fine on this machine (although I had to do some special configuration in xorg.conf to get it to work way back when I installed it.) However, it does not appear to be possible to manually configure X in 10.04. I tried disabling the splash screen in grub based on suggestions I found for other Ubuntu versions, but that had no effect on the problem.
Is it possible to replace X with the most recent version that could still be manually configured? Would anyone know how to go about doing that?
Alternatively, if it's impossible to get this old machine to run new versions of Ubuntu, has anyone had success with (relatively) new versions of other distros on it?
View 9 Replies
View Related
Aug 2, 2010
Though under Windows my Internet connection works fine and fluent under Debian linux it connects and disconnects repeatedly at short amounts of time. It didn't used to be like that but at a certain time i was forced to install pppoeconf to get my DSL internet connection going, after that even if i've uninstall pppoeconf and now i'm only using nm-applet to monitor my internet connection i still have this annoying problem.
View 1 Replies
View Related
May 28, 2011
I have all of the code written for a text based game but how big of a leap is it from text to graphics? lets just say a 2d engine. Is this a fairly easy task or would it be a bit of effort? I've never done anything with graphics before and would just like a quick idea of how much of a project is graphics vs functionality.
View 5 Replies
View Related
May 3, 2011
I've been trying to understand pthread in C a little better. So I made a simple program that takes in a string from the command line and creates a thread to print the string. I've looked online and copied the basic concepts but there are something things I'm confused about. The programs works just fine, but I have questions. Here's what I have so far.
[Code]....
One thing I'd like to know is why the 3rd argument in the pthread_create function which is my SendMessage function needs to be typecasted to a void pointer and then send the address of the function. Also as for the 4th argument, I would see typecasting to void pointer in some of the pthread examples I saw online, but in my case I'm passing a char pointer, would this be correct? In which case would I ever want to pass a void pointer?
Do I need a pthread_exit(NULL) in my main and in the SendMessage function? If so, why? I added the sleep() function so that I could let the pthread_exit function in my SendMessage function execute first. I simply saw that the online examples on pthread had pthread_exit() in both locations.
View 6 Replies
View Related
May 8, 2011
I want to capture short randomly occurring events such as Sudden Interstellar Disturbances, Lightning, ion counting, etc. To do this I wish to use the LINE-IN port. My sensor would feed a signal of less that 2 volts but could be submitted via a voltage divider. Since the sound card captures 44100 events per second this should capture events I am looking at, I think, but maybe not. I would capture the sound buffer to a string or memory buffer every second (and half second so I can prevent overwriting of its buffer, then merge the two).
Every 60 seconds (for validation) I would run "time" and count full buffer transfers in between to time events. By effectively counting characters from the beginning of the processing buffer to the beginning of the event I could further refine the "time to event". I think I could then save a decent number of values or until no data received from the processing buffer to preserve the event. This I would output with event time (to within 1/44100 sec) along with the data points captured to a file.
Except for the outputting of info to a file I think I can scan a buffer for events within a second (while LINE-IN continues capturing data on that port). I believe I have a way to handle the outputting. I am asking if any of the processing of the previous buffer would interfere with the sound cards data capture on LINE-IN? There would be no disabling of interrupts. I am presuming that system interrupts would not effect the LINE-IN data capture. Is this true?
View 6 Replies
View Related
Nov 21, 2010
how can I store the output of (ty to colucix for this line)
Code:
xprop -id $(xprop -root | awk '/_NET_ACTIVE_WINDOW(WINDOW)/{print $NF}') | awk '/_NET_WM_PID(CARDINAL)/{print $NF}'
in a variable and then pass the value of that variable to the kill command as the PID to kill?
View 3 Replies
View Related