Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Want help in Multithreading

Status
Not open for further replies.

rainbow5

Technical User
Dec 6, 2003
1
US
Hi,

I have two functions A and B, which I want to run concurrently from a program. Can anybody tell me how this program can be implemented using the UNIX signal, alarm, setjmp, and longjmp functions (and not using POSIX thread library).

Thanks,
RB
 
Roughly speaking, your alarm handler does
- setjmp() to preserve the context of the 'thread' you left
- longjmp() to restore the context of the 'thread' you want to resume

And you just keep alternating back and forth between them

--
 
Hi,
Please remember that what you are implementing with SETJMP, LONGJMP are called FIBERS. They are USERLAND threads. The kernel still only sees one thread and process.

If you have a MULTI CPU system ( it will only use 1 CPU to run your prcess ).

If one FIBER stalls like waiting for a resource, the whole process will stall. Now maybe your ALARM() mechanism might over come this.

There are PUBLIC DOMAIN FIBER packages you may want to look at. Why reinvent the wheel.


Using POSIX threads you can actually have 2 threads executing independent of each other within a process and can execute on more than 1 CPU of the system on multiple CPU systems at the same time.

If one stalls waiting for a resource the other thread isn't affected.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top