English 中文(简体)
(C) 利用ema光防止种族状况
原标题:Using semaphores to prevent race conditions (in C)
  • 时间:2012-04-20 04:06:25
  •  标签:
  • c
  • semaphore

因此,这是一个真正简单的问题。 我试图利用ema虫来防止种族状况。 我尝试阅读这些单页,但确实令人困惑。 难道有人可以简单地解释他们如何工作?

最佳回答

I assume you are using in Linux/Unix. Semaphores are used to control/restrict the access to a shared resource (lets say a global variable) from multiple threads. One Thread can take semaphore, modify the value and release it If another thread tries to access the variable, it should acquire the semaphore, if its already aquired, it is pended and gains access after the previous thread relinquishes control.

这样,甲型磷就被用于排序作业和变数的完整性。

Semaphores are also used to signal events from one thread to another. Mutex are variants of semaphore, where the same thread acquires and release it (to protect critical section or race conditions)

更 正

问题回答

我目前正在我的系统二类中讨论这个议题,该类基本上使用C语文编制方案。 正如我的教员向我们解释的那样,一种麻.症是一种非负面的ger化同步变量,它基本上有助于控制某些阅读功能。 我知道,这在某种程度上模糊不清,但所有内心的恐惧都被用来规范read活动,特别是在利用相对较小的缓冲器时。 我希望我会把你召集起来(0-0)。

A couple of examples of what I mean:

• 失眠:非负面的消化同步变量。

• sem_wait(s):[在(s=0)等待期间; s-;]——原称P(),荷兰语“Proberen”(考试)

• sem_post(s): [ s++; ]

– Originally named V(), Dutch for "Verhogen" (increment)

– OS guarantees that operations between brackets [ ] are executed indivisibly.

CREDIT/CITATION:Phillips博士,Joseph,DePaul大学,讲师(2014年)





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签