14 Topics
|
|
Sometimes you want to ensure that only one copy of a script can be run at time. Windows provides a facility called a mutex and you can use it to prevent multiple instances. To create the mutex, all I have to do is varname = GetMutex() If the mutex already … |
|
Hello, I wonder how we can use lock objects between 2 different applications. In the example below we can use lock objects to let only one thread to execute the code inside the lock object at a time. This works fine within one application. Now I wonder how we can … |
|
I have 2 processes (producer and consumer) sharing an int deque in shared memory, I have the producer process put 2 numbers in the deque and then it gets in a wait state losing its mutex lock. I then have the consumer process removing the numbers and printing them. It … |
|
Hi, I have two threads A and B. Thread A prints only odd numbers. Thread B prints only even number. I want to synchronize it in such a way that on the screen I get continues numbers. How can I do that? I was thinking of using sockets. Thread A … |
|
The assignment is to implement the Banker's Algorithm using pthreads and mutex locks. We implemented the Banker's Algorithm and it works fine. When we began implementing the pthreads and mutex locks we ran into problems. We know that each process is a thread, and that the mutex lock is acquired … |
|
Can I use semaphore or mutex on MikroC? If you know , please tell me the function name or exsample code. |
|
Hi all! This is a simple piece of code that I wrote about a year ago, in response to a question on Daniweb. I decided to infuse it with some C++11 magic, which led to a pretty sweet code snippet, full of neat little techniques you might want to use, … |
|
Hi folks, I need a solution for following scenario. 1. Suppose two processes running simulteneously. 2. Process (P1) has already locked a mutex (M1). 3. Process (P2) is trying to lock same mutex (M1) but as it is already locked by (P1), P2 is waiting for unlocking (M1). 4. Now … |
|
[CODE] sem_t w,r,s1,s2,s3; pthread_mutex_t m; int main(int argc, char* argv[]) { mutex and semaphores initialization ..... call threads.... wait until finish and cancel threads... clean threads and semaphores [I]exit;[/I] } void *reader(void *argv) { while(TRUE) { sem_wait(&r); sem_wait(&s1); pthread_mutex_lock(&m); ... read data..... pthread_mutex_unlock(&m); sem_post(&s1); sem_post(&w); } printf("Done read\n"); sem_post(&extra2); pthread_exit(NULL); … |
|
This snippet shows how to use Mutex to prevent multiple copies of your software from running. For a WinForms application, this code goes into the Program.cs file. The magic starts in line 14 where we attempt to create a Mutex. A Mutex is a form of a lock, but it … |
|
Hi there, I'm working on a project which incorporates the following: [LIST] [*]Reading data from XML [*]Writing data to XML [*]Interpreting XML and passing the information to various places [/LIST] These are on different threads, and I've used a Mutex to make sure they don't try opening the main XML … |
|
Hi, I would like to make an threaded app which would use pthreads. I made a linked list and I put references to running threads here. I know that operations of adding a new thread reference to the list and removing a thread reference from the list after the thread … |
|
I have a static function that write to a log file . In my project I am already using multithreading , hense I m getting exception that 'process can't access file because it is being used by another process ' I want to mutex that code so that if one … |
|
Basically I am trying to learn multithreading in C++. Platform: Windows XP. So far so good but I want to make sure I'm using mutex correctly. It compiles and runs as expected, but just wanted to make sure I use the CreateMutex() function in the correct place. Thanks! Here's my … |
The End.