Based on the code context, I can explain the difference between hb_mutexSubscribe() and hb_mutexSubscribeNow() in Harbour's multi-threading system.
Understandinghb_mutexSubscribe()vshb_mutexSubscribeNow()Both functions are part of Harbour's mutex notification system, but they behave differently:
The key difference is that hb_mutexSubscribeNow() first checks if there's already a notification in the queue before waiting, making it useful when you want to process any pending notifications without necessarily blocking.
Usage ExampleLooking at the code in tests/speedtst.prg, we can see an example of how hb_mutexSubscribe() is used: speedtst.prg:457-460
This code waits for a job notification on the mutex. If the notification value is NIL, it exits the loop.
Implementation in xHarbour Compatibility LayerThe contrib/xhb/hbcompat.ch file shows how these functions are translated for compatibility with xHarbour: hbcompat.ch:152-157 hbcompat.ch:158-163
These translations show that both functions have similar parameters but different behavior. The timeout parameter is converted from milliseconds to seconds when translating from xHarbour to Harbour.
Function DeclarationsBoth functions are declared in Harbour's core API: harbour.hbx:714-715
And they're also exported in the Harbour DLL: harbour.def:907-908
Practical Use CaseThe main practical difference is:
This is particularly useful in producer-consumer scenarios where you might have multiple notifications queued up and want to process them all without waiting unnecessarily.
Notes