|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Semaphores/Threads
Anyone one know where I can find an implementation of a semaphore using thread/pthread library in C for UNIX (I would like to use these semaphores in other programs)? Or, anyone have any ideas on how to implement one? I would really appreciate it. Thanks.
|
|
#2
|
|||
|
|||
|
I'm not sure that I understand the question, but I'll try to make a few remarks anyway....
A semaphore is thing that is usually implemented in the kernel. You need to be able to atomically test for zero and decrement. That can only be done in assembler. And you generally want the ability to sleep the process until the semaphore is non-zero and you really need the kernel for that. So a semaphore might be used in conjunction with pthreads. But implementing it out of pthreads does not make sense. Threads are usually syncronized via mutexes. But they can use semaphores. There are two styles of semaphores on unix. The first is the System V semaphores. "man semget" and "man semctl" should bring up some info about them. A second style of semaphores comes from the Posix real-time extentions. They may not be on every version of Unix, especially the older versions. But "man sem_wait", "man sem_try", and "man sem_post" should bring up info about them if they exist. |
|
#3
|
|||
|
|||
|
I would like to implement the "wait" and "signal" operation of theoretical semaphores using the pthread library. Thanks.
|
|
#4
|
|||
|
|||
|
So are you looking for implementation examples for pthreads........you should be able to find umpteen examples by doing a simple google search.......herez a link that I think would help u......
URL Hope this helps |
|
#5
|
|||
|
|||
|
|
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Semaphores/Threads |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|