I can not take a critical section [duplicate] - windows

This question already has answers here:
Critical section negative lock count
(2 answers)
Closed 7 years ago.
I have a thread stopped taking a critical section. The critical section does not have any thread owning, the only strange thing is that LockCount is -3.
LockCount -3
RecursionCount 0
OwningThread 0
LockSemaphore dfc
SpinCount 10000
Inside debug info the ContentionCount is 1.
How can I get a lockCount of -3? any idea?
Thank you.

Yes. You released it more times than you acquired it.
It's a good idea to use a scoped guard to auto-release it. Then you don't have to worry about multi release.

Related

How many RFNoC blocks can be added to a x310 USRP?

This is a question I've been trying to get an answer for some time.
Is there any limit to the number of RFNoC blocks that can be added to a x310 USRP?
To cite the source code you'd need to be modifying to add your own blocks:
https://github.com/EttusResearch/fpga/blob/maint/usrp3/top/x300/rfnoc_ce_auto_inst_x310.v#L1:
localparam NUM_CE = 10; // Must be no more than 10 (6 ports taken by transport and IO connected CEs)
You can't have more than ten blocks.

How to free memory in go? [duplicate]

This question already has answers here:
Setting pointers to nil to prevent memory leak in Golang
(2 answers)
Closed 5 years ago.
I've started to learn Go, and found something I'm not able to find info about.
For example, if I'm making my own list structure
type elem struct {
prev *elem
next *elem
value string
}
And adding new elements to it with
Current.next = &elem{}
How should I remove them? I mean, how can I remove data of elem from memory, not just from the list?
Go has garbage collection. It will scan for data that has no pointer to it and remove it from heap (Garbage collector is running beside your program). The only thing you should do is:
Current.next = nil
Your elem{} will be removed from memory eventually after you remove all pointers to it (It's not deterministic. Can't tell exactly when elem{} will be released). There are different implementations of garbage collection; Go's implementation may change at any time.
If Current goes out of scope, you don't even need to set next to nil.

Empty function in golang [duplicate]

This question already has an answer here:
Function signature with no function body
(1 answer)
Closed 7 years ago.
Was looking at the source code go source code, below is a snippet from sleep.go (package time):
package time
// Sleep pauses the current goroutine for at least the duration d.
// A negative or zero duration causes Sleep to return immediately.
func Sleep(d Duration)
// runtimeNano returns the current value of the runtime clock in nanoseconds.
func runtimeNano() int64
How is it possible that func Sleep(d Duration) doesn't have any implementation? Where can I find the exact implementation of Sleep function?
Edit: The answer can be found in the 2 links provided by #DaveC. However please read the comments below to see the explanation about why empty function can't be replaced with Go even after bootstrapping Go (1.5)
Considering what Sleep() does (it deschedules a golang thread for a given amount of time), you can't express that it in go, so it's probably implemented as some kind of compiler instrinsic.
Whoa, lots of downvotes here. It looks like Sleep is in fact implemented in assembly.

What may happen if sem_destroy() is not invoked on a semaphore in C? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
This is regarding to semaphore programming in C language.
sem_t mutex;
.
.
int main()
{
sem_init(&mutex, 0, 1);
.
.
.
.
sem_destroy(&mutex);
return 0;
}
If I do not use sem_destroy() at the last of my programs, what implications it may cause?
It is operating system specific. On Linux, read sem_overview(7); actually you are in an unspecified case. However, the documentation says
Before being used, an unnamed semaphore must be initialized
using sem_init(3). It can then be operated on using
sem_post(3) and sem_wait(3). When the semaphore is no longer
required, and before the memory in which it is located is
deallocated, the semaphore should be destroyed using
sem_destroy(3).
so you should call sem_destroy when appropriate; don't risk having a system-wide resource leak. BTW documentation of sem_destroy(3) tells:
An unnamed semaphore should be destroyed with sem_destroy() before
the memory in which it is located is deallocated. Failure to do this
can result in resource leaks on some implementations.
For named semaphores, things are different (they sit in /dev/shm/). I guess that a thread-shared semaphore might be destroyed when its memory segment is removed (no more mapped by any process). I am not sure of this and it is implementation specific behavior, so don't rely on this.
Use also proc(5).
So what may happen is a system-wide resource leak and you don't want it. You might need to reboot to remove it. BTW, you could use strace(1) to find out the actual syscalls involved, and you could look into the source code of your GNU glibc (or some other libc, like musl-libc) - and perhaps of the Linux kernel- to understand more the implementation specific behavior.
Avoid undefined behavior.
The address where Semaphore is stored will hold the last value of the semaphore if you dont use sem_destroy ...
It might cause problems as the semaphore's previous value might be indicating that a process is still running even if it is not !

Process priority in Linux kernel [duplicate]

This question already has an answer here:
what is the difference among three priorities used in Linux kernel?
(1 answer)
Closed 6 years ago.
I am new to Linux kernel and I have got confused . Please can anyone give answer to my questions :
Q1 -> Is static priority of a thread changes or not ? If changes then how it changes ?
Q2 -> What is the default value of static priority and dynamic priority for a process and thread in Linux kernel ?
Q3 -> What is the initial value of static priority and dynamic priority for a newly created thread and process?
Q4 -> When we talk about the priority of a process or thread (incrementing / decrementing priority , setting priority etc. ) , then which priority we are referring , is it static priority or dynamic priority ?
For currently running process, please run the below command
renice <priority_value> -p `pidof <process_name>`
Here, -20<=priority_value<=19
For new process
nice -n <priority_value> <process_name>

Resources