Sponsored Content
Full Discussion: producer-consumer problem
Top Forums Programming producer-consumer problem Post 302270231 by joey on Saturday 20th of December 2008 08:09:18 AM
Old 12-20-2008
what if i use semget semop and not use pthread_mutex_lock..
shall it work?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Producer/Consumer

Hi all, I have an Producer/Consumer program in C(using shared memory and semaphores).It is working fine with sleep calls after every read/write operation.Each one is a independent program.Now if i remove the sleep calls in consumer,it goes on waiting in the loop till the producer puts some valid... (3 Replies)
Discussion started by: poorni_uma
3 Replies

2. UNIX for Dummies Questions & Answers

Slow Producer - Fast consumer

I would like to loop through a set of directories, performing operation(s) on each one. The basic script** is dirs=`find . -name .svn -print` for f in $dirs; do echo "Processing $f directory .." done Fine and dandy, but here is the problem: the find expression must complete... (2 Replies)
Discussion started by: jakeo25
2 Replies

3. Programming

producer consumer

Control two exclusively shared resources. The two resources are two files. The producer will write even numbers to one file, and odd numbers to another one. The consumer respectively reads from each file until it gets 5 even numbers and 5 odd numbers. Can any one help me with the code. ... (0 Replies)
Discussion started by: gokult
0 Replies

4. Shell Programming and Scripting

producer consumer

Control two exclusively shared resources. The two resources are two files. The producer will write even numbers to one file, and odd numbers to another one. The consumer respectively reads from each file until it gets 5 even numbers and 5 odd numbers. Can any one help me with the code. ... (1 Reply)
Discussion started by: gokult
1 Replies

5. UNIX for Advanced & Expert Users

producer consumer

Control two exclusively shared resources(semaphore). The two resources are two files. The producer will write even numbers to one file, and odd numbers to another one. The consumer respectively reads from each file until it gets 5 even numbers and 5 odd numbers. Can any one help me with the... (0 Replies)
Discussion started by: gokult
0 Replies

6. Programming

producer consumer semaphore

Control two exclusively shared resources(semaphore). The two resources are two files. The producer will write even numbers to one file, and odd numbers to another one. The consumer respectively reads from each file until it gets 5 even numbers and 5 odd numbers. Can any one help me with the... (0 Replies)
Discussion started by: gokult
0 Replies

7. UNIX for Dummies Questions & Answers

producer consumer

Control two exclusively shared resources. The two resources are two files. The producer will write even numbers to one file, and odd numbers to another one. The consumer respectively reads from each file until it gets 5 even numbers and 5 odd numbers. Can any one help me with the code. ... (3 Replies)
Discussion started by: gokult
3 Replies

8. Homework & Coursework Questions

producer consumer semaphore

Control two exclusively shared resources(semaphore). The two resources are two files. The producer will write even numbers to one file, and odd numbers to another one. The consumer respectively reads from each file until it gets 5 even numbers and 5 odd numbers. Can any one help me with the... (1 Reply)
Discussion started by: gokult
1 Replies

9. UNIX for Dummies Questions & Answers

Abnormal producer consumer problem driving me nuts

normally, i hate asking someone to do my homework for me but am getting desperate right now. i have a project about consumer producer problem. the deadline is tonight at 23:55. but i havent gotten it working yet. i just COULDNT get it to work right yet. the problem is as follows: the C - program... (0 Replies)
Discussion started by: alexantosh
0 Replies

10. Homework & Coursework Questions

Abnormal producer consumer problem driving me nuts

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: normally, i hate asking someone to do my homework for me but am getting desperate right now. i have a project... (1 Reply)
Discussion started by: alexantosh
1 Replies
semget(2)							System Calls Manual							 semget(2)

Name
       semget - get set of semaphores

Syntax
       #include <sys/types.h>
       #include <sys/ipc.h>
       #include <sys/sem.h>

       int semget (key, nsems, semflg)
       key_t key;
       int nsems, semflg;

Description
       The  system  call  returns the semaphore identifier associated with key.  A semaphore identifier and associated data structure and set con-
       taining nsems semaphores are created for key, if one of the following is true:

       o   The key is equal to IPC_PRIVATE

       o   The key does not already have a semaphore identifier associated with it, and (semflg & IPC_CREAT ) is true.

       For further information, see

       Upon creation, the data structure associated with the new semaphore identifier is initialized as follows:

       o   The sem_perm.cuid, sem_perm.uid, sem_perm.cgid and sem_perm.gid are set equal to the effective user ID and effective group ID,  respec-
	   tively, of the calling process.

       o   The low-order nine bits of sem_perm.mode are set equal to the low-order nine bits of semflg.

       o   The sem_nsems is set equal to the value of nsems.

       o   The sem_otime is set equal to zero (0) and sem_ctime is set equal to the current time.

Return Values
       Upon  successful  completion,  a nonnegative integer, namely a semaphore identifier, is returned.  Otherwise, a value of -1 is returned and
       errno is set to indicate the error.

Diagnostics
       The semget system call fails if any of the following is true:

       [EINVAL]       The nsems is either less than or equal to zero or greater than the system-imposed limit

       [EACCES]       A semaphore identifier exists for key, but operation permission, as specified by the low-order nine bits of semflg would not
		      be granted.  For further information, see

       [EINVAL]       A  semaphore  identifier	exists	for key, but the number of semaphores in the set associated with it is less than nsems and
		      nsems is not equal to zero.

       [ENOENT]       A semaphore identifier does not exist for key and (semflg & IPC_CREAT ) is false.

       [ENOSPC]       A semaphore identifier is to be created but the system-imposed limit on the maximum number of allowed semaphore  identifiers
		      in the system would be exceeded.

       [EEXIST]       A semaphore identifier exists for key but ((semflg & IPC_CREAT ) & (semflg & IPC_EXCL )) is true.

See Also
       semctl(2), semop(2), ftok(3)

																	 semget(2)
All times are GMT -4. The time now is 02:03 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy