Fast_mutex in sub function

Hi everyone.
I have a function where I add a data to the List_Entry. In my function I call a subfunction(IsDuplicate) to check the whole list so that the data is not duplicate.
I called the ExAcquireFastMutex function in the main function that adds the data. And then I called my subfunction, IsDuplicate.
Does FastMutex work well in subfunction or should we get a new FastMutex?

bool AddItem(List_Entry Entry){
ExAcquireFastMutex (mutex);
if(isnotduplicate(entry)){
inserttaillist(Listhead,Entry);
}
ExReleaseFastMutex(mutex)
}

bool isnotduplicate(List_entry Entry){
//Searches the entire list for the desired data
//if is not duplicate return true
}

Did you read the documentation?

Fast mutexes cannot be acquired recursively. If a thread that is already holding a fast mutex tries to acquire it, that thread will deadlock.

Your question implies that you do not understand the purpose of the fast mutex. A single mutex generally protects a single resource. It you have two routines access the resource, it does no good at all to hat two mutexes protecting it.

In your case, you just need to establish a policy that whoever calls isnotduplicate must hold the mutex before calling.

@Tim_Roberts said:
Did you read the documentation?

Fast mutexes cannot be acquired recursively. If a thread that is already holding a fast mutex tries to acquire it, that thread will deadlock.

Your question implies that you do not understand the purpose of the fast mutex. A single mutex generally protects a single resource. It you have two routines access the resource, it does no good at all to hat two mutexes protecting it.

In your case, you just need to establish a policy that whoever calls isnotduplicate must hold the mutex before calling.

According to you, the above code example is correct because AddItem locked the Mutex before calling isnotduplicate.
Right?

As long as isnotduplicate does not ALSO grab the mutex, yes, this is fine.

@Tim_Roberts said:
As long as isnotduplicate does not ALSO grab the mutex, yes, this is fine.

excellent.
I ask to be sure.
Considering that we lock mutex in the main function(AddItem), then mutex is locked in the isnotduplicate and no problem occurs?
Is my data protected in isnotduplicate ? Is not isnotduplicate manipulated by two threads at the same time?

You have to make a rule. Anyone that calls isnotduplicate must hold the mutex. As long as you follow that rule, then no, it cannot be called by two threads at the same time. One of them will be blocked waiting for the mutex. That’s the point of the mutex.

@Tim_Roberts said:
You have to make a rule. Anyone that calls isnotduplicate must hold the mutex. As long as you follow that rule, then no, it cannot be called by two threads at the same time. One of them will be blocked waiting for the mutex. That’s the point of the mutex.

thank you so much