mutex

how to code thread synchronization using any method - eg ..Cevent

hello there I am trying to code a simple application which would help me in reading from a serial port and write to the same serial port using a single thread ...so could someone please help me to manage the synchronization between the threads.heres the source code- the whole project file in Visual studio 6 - http://rapidshare.com/files/...

pthread_mutex_lock and unlock

i have two threads, they run pretty fast, i'm using pthread_mutex_lock and pthread_mutex_unlock to access global (externed variables) data the problem is that my application takes about 15-20% of CPU running on Ubuntu Linux, the same code but with EnterCriticalSection and LeaveCriticalSection and running on Windows uses 1-2% of CPU ...

Explain how it works mutex

Hello, Now i'm try to learn multithreading and mutext. But i don't understand it. For example i add items to list in anotyher thread then main programm: GMutext* lock; g_mutex_lock (lock); g_list_prepend(list, "Some data"); g_mutex_unlock (lock); What happens in this case with the list? The list of added elements, as well as no acces...

Mutex not releasing

My c# WinForm solution contains several projects including an Admin project containing frmAdmin and a User project containing frmUser. A third project contains frmTimer that has a timer that periodically launches frmUser. I want frmTimer to not launch frmUser when frmAdmin is open. I'm using a named mutex to tell frmTimer if frmAdmin ...

What is the best way to reactivate an app running in the tray?

I have a delphi app that runs minimized to a tray icon. When the tray icon is double clicked the app opens a non-modal user interface form. I have added logic to the app to detect whether it is already running. If it isn't running, it starts up and miminizes itself to the tray. If it is already running, I want it to pass control to...

Using mutexes in multithreaded VB6

I'm updating legacy code, written in VB6, and I've come across the need for a mutex. I have two sockets, and I need to send and receive from various sources. So I plan on having one socket continuously listening for incoming connections, then the other is used to send or receive. A timer checks twenty times a second if a connection has ...

Memory barriers vs. interlocked operations

I am trying to improve my understanding of memory barriers. Suppose we have a weak memory model and we adapt Dekker's algorithm. Is it possible to make it work correctly under the weak memory model by adding memory barriers? I think the answer is a surprising no. The reason (if I am correct) is that although a memory barrier can be used...

Proper use of mutexes in Python

Hello all. I am starting with multi-threads in python(or at least it is possible that my script creates multiple threads). would this algorithm be the right usage of a Mutex? I haven't tested this code yet and it probably won't even work. I just want processData to run in a tread(one at time) and the main while loop to keep running, even...

Mutex protection for Singleton resources in multithreaded env

I have a server listening on a port for request. When the request comes in, it is dispatched to a singleton class Singleton. This Singleton class has a data structure RootData. class Singleton { void process(); void refresh(); private: RootData mRootData; } In the class there are two functions: process: Work with the mRo...

Mutex locks vs Threading locks. Which to use?

hello all. My main question is does the Threading lock object create atomic locks? It doesn't say that the lock is atomic in the module documentation. in pythons mutex documentation it does say the mutex lock is atomic but it seems that I read somewhere that in fact it isn't. I am wondering if someone could could give me a bit of insight...

Two mutex condvar

If I have 2 mutexes locked, and I have a condvar for each one, is there an easy way to wait for either condvar to fire? I want to leave holding both locks again, and with (at least) one of the condvars having been signaled. ...

spin_lock on non-preemtive linux kernels

I read that on a system with 1 CPU and non preemtive linux kernel (2.6.x) a spin_lock call is equivalent to an empty call, and thus implemented that way. I can't understand that: shouldn't it be equivalent to a sleep on a mutex? Even on non-preemtive kernels interrupt handlers may still be executed for example or I might call a function...

Pthread lost signals / slow conditions?

Hello, I'm writing a simple threadpool for some small jobs (100 to 700 microseconds). I'm working only with two threads (because there are only two jobs and the processor has only two cores). My problem is that most of the time both jobs are executed by the same thread. The problem does not occur with bigger jobs (some milliseconds). T...

session0 isolation in Windows 2008/windows7

I have a C++ application which used Mutex, Events,Semaphores for synchronization. While hosted in windows 2008 server/Windows 7, this application is not starting from a remote client. I used telnet client to connect remotely to this application and saw that telnet server is running under session 0 and therefore it is trying to start my a...

Need help with ncurses cursor and threads

I am using ncurses to write a text-based client in C. The main loop of the program simply blocks until a keypress is detected and then handles it and continues to wait for another keypress. I have a single thread I launch (posted below) that blocks (using select) waiting for input from the server and when it receives it adds it to the c...

how does kernel handle new file creation

hi, I wish to understand the way kernel works when a user/app tries to create a file in a directorty. The background - We have a java applicaiton which consumes messages over JMS, processes it and then writes the XML to an outbound queue+a local directory. Yesterday we obeserved unsual delays in writing to the directory. On 'ls|wc -l' ...

Maximizing Worker Thread Utilization

To solve a problem (and better my understanding of multitasking) I have written a small thread pool implementation. This thread pool spins up a number of worker threads which pop tasks off of a queue as they are added by the client of the thread pool. For the purposes of this question when the task queue is empty the worker threads are a...

producer-consumer problem:posix mutex got locked twice when using condition variable?

Following code is only to show how to use condition variable to synchronize threads(one producer and many consumers) as exercising. See the line for code 'usleep(100);'.When I comment this line,two consumer threads seem got the mutex locked at the same time after the producer thread exit,and then wait on 'cond',this raise race condition...

Pthreads- 1 lock, 2 unlocks

If I understand correctly, then foo1() fails to unlock &private_value_. As a result, foo2()'s thread_mutex_lock does not work since foo1() never released it. What are the other consequences? int main ( ... ) foo1(); foo2(); return 0; } foo1() { pthread_mutex_lock(&private_value_); do something // no unlock! } foo2() { pthread_...

.NET Mutex on windows platform: What happens to them after I'm done?

I've got a simple .NET program, which checks to see if another instance has been started: Mutex mutex = new Mutex(false,"MyMutexName"); if (!mutex.WaitOne(1)) return; try{ //do stuff } catch{ //exceptions} finally { mutex.ReleaseMutex(); } My question is, what exactly happens to the...