Logo

Programming-Idioms

History of Idiom 22 > diff from v101 to v102

Edit summary for version 102 by programming-idioms.org:
Restored version 100: OT.

Version 101

2020-11-09, 08:52:56

Version 102

2020-11-09, 10:17:06

Idiom #22 Convert string to integer

Extract integer value i from its string representation s (in radix 10)

Idiom #22 Convert string to integer

Extract integer value i from its string representation s (in radix 10)

Variables
i,s
Variables
i,s
Extra Keywords
int base conversion
Extra Keywords
int base conversion
Code
#include <pthread.h>
#include <semaphore.h>
#include <stdio.h>

/*
This program provides a possible solution for first readers writers problem using mutex and semaphore.
I have used 10 readers and 5 producers to demonstrate the solution. You can always play with these values.
*/

sem_t wrt;
pthread_mutex_t mutex;
int cnt = 1;
int numreader = 0;

void *writer(void *wno)
{   
    sem_wait(&wrt);
    cnt = cnt*2;
    printf("Writer %d modified cnt to %d\n",(*((int *)wno)),cnt);
    sem_post(&wrt);