I need to model some portion of my hardware in systemverilog and it kind of looks like following:
I can have two treads -(SV task) running in parallel.
Thread:
1. get_resource_from_manager() [sema.get(1) ??]
2. repeat(until_finish)
3. do_work()
4. give_contorl_to_thread1() [sema.put(1) ??]
5. wait_for_thread1_to_return_control() [sema.get(1) ??]
6. continue_work()
7. endrepeat
8. do_some_cleanup()
9. exit()
Both Threads do the same work. I am thinking about using semaphore. I've never used it before. Is it a valid assumption/fact that the thread will block at line 5? What I wanted to achieve is, thread1 will give up resource to thread2 by using semaphore put() in line 4 -> thread 2 will pick up this resource and do it's work and eventually release it using put. In between this time, thread1 will be waiting on blocking get() call at line 5.