Hey guys I was wondering if someone could provide a little help.
I've been trying to teach myself pthreads and with that, mutex locks to get threads running together and using the ... |
I am writing a program with a few critical sections. The thing is I need to check the value of a mutex in an if statement.
I would like to do ... |
Here is the code:
....
typedef struct {
int buf[10];
long head, tail;
int full, empty;
pthread_mutex_t *mut;
pthread_cond_t *notFull, *notEmpty;
} queue;
int main(){
queue *que;
pthread_t ...
|
I've the following source code (adapted from my original code):
#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include "pthread.h"
#define MAX_ENTRY_COUNT 4
int entries = 0;
bool start = false;
bool send_active = ...
|
Suppose there are two threads, the main thread and say thread B(created by main). If B acquired a mutex(say pthread_mutex) and it has called pthread_exit without unlocking the lock. So ... |
Using pthreads, how would one, in C, initialize a static array of mutexes?
For a single static mutex, it seems I can use PTHREAD_MUTEX_INITIALIZER. But what about an static array of them? ... |
I'm trying to implement a binary tree supporting concurrent insertions (which could occur even between nodes), but without having to allocate a global lock or a separate mutex or mutexes for ... |
|
We are trying to port some code from Solaris to HPUX. While Solaris uses it's own thread API, HPUX uses the Pthread API. One problem that we faced during migration is ... |
I am confused about use of multiple mutexes in C.
int main() {
pthread_t thread1;
char *message1 ...
|
|
Code: #include #include #include #include #define N 3 /*Declaration*/ void *writer(int n); void *reader(int n); void clean(); /*Init*/ pthread_mutex_t mutex,mutex1; int main(int argc, char **argv) { int i; pthread_t thrR[N]; pthread_t thrW[N]; pthread_mutex_init(&mutex,NULL); pthread_mutex_init(&mutex1,NULL); for(i=0;i |
|
#include #include #include #include pid_t pid; pthread_mutex_t imutex; pthread_mutexattr_t attr; int main(int argc, char **argv) { pthread_mutexattr_settype(&attr ,PTHREAD_MUTEX_RECURSIVE); pthread_mutex_init(&imutex,&attr); pid = fork(); printf("pid %d",pid); if (pid == 0){ while(1){ pthread_mutex_lock(&imutex); printf("\ni am the child\n"); pthread_mutex_unlock(&imutex); } } else{ while(1){ pthread_mutex_lock(&imutex); printf("\ni am the parent\n"); pthread_mutex_unlock(&imutex); } } return 0; } |
|
|
|
Isn't it obvious from the manual page ? Like any other consumable resource, like say calling malloc and then calling free, you're probably going to get away with sloppy code which doesn't clear up properly, especially in smaller programs. But problems associated with such poor code usually show up at the most inconvenient times (during presentations, 1 day after delivery to ... |
I created a dynamic allocated data structure (link list nodes) that is accessed by many threads and I would like to protect data of each nodes using mutex variable. Here's what my data record for a node looks like: typedef struct node_s { pthread_mutex_t node_mutex; int node_val; struct node_s *next; } node; A node's data is dynamically allocated using malloc() and ... |
|
Hi there, I have a question about protecting shared data between threads. I have written a threaded tcp server. and it reads and writes to vectors. i'm unable to find any clear documentation on the web on this. What is this created mutex protecting ? Do i have to create a new mutex for every global variable ? this is a ... |
Hello, I'm trying to implement pthread mutex. The follwing small program is supposed to ask for a name and print it out: /////////////////////////// #include pthread_mutex_t name1=PTHREAD_MUTEX_INITIALIZER; #define NUM_THREADS 2 pthread_t threads[NUM_THREADS]; void *Print(void *threadid) { char name[20]; cout<<"\n Please Enter Your User Name ,User "<>name; cout<<"\n"< |
|