Guest
Is it possible to do that?
Thank you.
Thank you.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Yes and no.Is it possible to do that?
Thank you for a good example.On Sat, 31 Jan 2009 12:16:33 -0800 (PST), wrote:
Is it possible to do that?
Yes and no.
SV semaphores are dynamically created - they have
a "new" function - and there is no way to get that
effect in regular Verilog. But you could almost
certainly work around it by creating a static
pool of semaphores and handing out one of them
whenever their "new" method was called,
or simply by statically creating each semaphore
that you know you will need.
More important, though, is the question of
the mutual exclusion behaviour of a semaphore.
It's quite tricky to get that right in Verilog
because the language allows arbitrary interleaving
of execution of concurrent threads, but you can find
plenty of rigorous solutions by consulting any standard
text on concurrent programming (I like Ben-Ari,
Principles of Concurrent and Distributed Programming,
but it's quite old and may be out of print by now).
Googling for "mutual exclusion" and "bakery algorithm"
will probably be useful too.
For some real, practical problems you can get away
with a much simpler implementation that is not
rigorously reliable and not truly general. As an
example, consider a static task that must be
executed by no more than one process at a time:
task T(...); // static task
reg mutex; // static variable
begin
if (mutex) // Someone else has the lock.
wait (mutex === 1'b0); // Wait for my turn.
mutex = 1'b1; // Claim the lock.
<<< do the real work of the task
mutex = 1'b0; // Release the lock.
end
endtask
It is an interesting and instructive exercise to work out
(a) how this works,
(b) how it can go wrong (it can, in many different ways!)
Once you've done (b) to your own satisfaction, you will be
ready to read the academic texts on how to do it properly!
good luck
--
Jonathan Bromley, Consultant
DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services
Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.brom...@MYCOMPANY.comhttp://www.MYCOMPANY.com
The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
That is usually a good idea, but it does not help if you needProbably, the solution of this puzzle is to replace static task with
automatic one?
I suppose something like that could be whipped up using a wire asIs it possible to do that?
I wrote this when I was a kid in verification. Have a look @Is it possible to do that?
Thank you.
OK, so now you're not a kid perhaps youOn Feb 1, 1:16 am, sasha.kan...@gmail.com wrote:
Is it possible to do that?
Thank you.
I wrote this when I was a kid in verification. Have a look @
http://testbench.in/tTB_27_VERILOG_SEMAPHORE.html
It seems as if my newsreader ate my reply here. Anyway, I thought thisThat is usually a good idea, but it does not help if you need
to get exclusive access to a shared resource. Like I say -
read the standard texts on concurrent programming!
Hmm, after thinking a bit more about this I believe that there are somemodule lock;
// I haven't checked the Verilog standard, but I assume that reads/writes
// to an integer is atomic.
integer new_id = 0;
integer final_id = 0;
reg pulse_lock = 0;
task automatic lock;
input integer ID;
begin
while(final_id != ID) begin
new_id = ID;
@(pulse_lock); // Wait for serialization
end
end
endtask
// This procedure serializes access to the lock
reg locked = 0;
always @(new_id) begin
if(!locked) begin
locked = 1;
final_id = new_id; // This ID acquired the lock
pulse_lock = !pulse_lock; // Wake up all all threads that may be
// listening
end
end
task unlock;
begin
final_id = 0;
locked = 0;
pulse_lock = !pulse_lock; // Wake up anyone else who is trying to
// access the lock.
end
endtask
endmodule
I cannot find the solution for now. Does it exists in Verilog 2001Hmm, after thinking a bit more about this I believe that there are some
race conditions in this version as well. I still believe that the locking
is fairly solid, but there seems to be some race possibilities when
unlocking the lock.
This was even trickier than I thought in the beginning...
/Andreas- Hide quoted text -
I have thought a bit more about how to synchronize tasks in Verilog andThis was even trickier than I thought in the beginning...
I have thought a bit more about how to synchronize tasks in Verilog and
I have come up with the following attempt.
[snip]