Vous êtes sur la page 1sur 1

Exercise1:CreateaHelloWorldprogramusingthreads

Exercise2:Modifyexercise2,toprintthethreadidofthethreadsalongwiththeHello
Worldmessage
Exercise3:Writeaprogramhellomany.cthatwillcreateanumberNofthreadsspecifiedin
thecommandline,eachofwhichprintsoutahellomessageanditsownthreadID
Exercise4:Writeaprogramusingthreads,wherethemainthreadincrementsthevalue
andthechildthreaddecrementsthesamevalue.
Exercise5:Giventwocharacterstringss1ands2,useCandpthreadtowriteaparallel
programtofindoutthe numberofsubstrings,instrings1,thatareexactlythesameas
strings2.Thestringsareendedwith\0.Forexample,supposenumber_substring(s1,s2)
implementsthefunction,thennumber_substring(abcdab,ab)=2,number_substring
(aaa,a)=3,number_substring(abac,bc)=0.Supposethesizeofs1ands2aren1
andn2,respectively,andpthreadsareused,weassumethatn1modp=0,andn2<
n1/p.

Stringss1ands2arestoredinafilenamedstrings.txt.Strings1isevenlypartitionedfor
pthreadsto concurrentlysearchformatchingwithstrings2.After athreadfinishesits
workandobtainsthenumberoflocalmatching,thislocalnumberisaddedintoa
globalvariableshowingthetotalnumberofmatchedsubstringsinstrings1.Finallythis
totalnumberisprintedout.Theformatofthestrings.txtislikethis(thefirststringiss1
andthesecondoneiss2):
abcassghbcaj
bca
Intheprogram,use#definetospecifynumberofthreadstobecreated.Forexample,
#defineNUM_THREADS5
Exercise6:Givenanarrayofintegers,useCandpthreadtowriteaparallelprogramto
findoutthesumofthearrayandthesecondmaximum.Assumetheentirearrayisstore
dinitiallyinonelocationandisdistributedtothedifferentthreadsforparallelprocessing.

Vous aimerez peut-être aussi