I have this struct
Code:
typedef struct
{
int gifts_num; //Let's say buffer size
char Gifts[100][128]; //Half function buffer
int elfsOnIt; //Consumer processes (as mutex)
}bucket;
My program at first creates many buckets, every bucket has an array of strings(Gifts), a number that shows the quantity of strings (gifts_num) and a variable shows how many child processes working on it.
The parent process creates all the arrays of all buckets playing the role of producer.(I 've already done this)
Children processes have to pick one string at a time and place it into a bag.
In this time i have only Consumers so the problem limited to multiple consumers.
The problem is that only one process must access the (Gifts) at a time.
Is it correct to use elfsOnIt as mutex ?
Is it correct to use gifts_num as buffer size ?
i think that using only mutex semaphore is enough to do my job. I create 2 plans and i need your suggestions
Plan A
P(full)
P(mutex) //elfsOnIt as mutex
//Critical Section
V(mutex)
V(empty) //gifts_num as empty
I think that full and empty aren't necessary because i only use Consumers and the problem is limited to that "only one at a time". So i made plan B
Plan B
P(mutex) //elfsOnIt as mutex
//Begin CS
//bla...bla...bla
gifts_num--
//End CS
V(mutex)
I think that is better because after picking (or emptying) a string array i don't care about refilling. In simple words, array string is not fully functionable buffer because i only pick, not put things. After picking all stuff from it is useless for me.
I am pretty sure (so far) that plan B is better for this specific occasion but i 'll wait for your suggestion.
*Just to mention I use share segments.