>Hi
>I have written a program which receives mails from server using POP3.
>it's downloading sequentially. now i want to use the multithreading
>in this regard where i can create threads for each and every
>mail...and download those mails simaltaneously.
>if u have any idea please help me out.
First, be careful to to share resources without synchronization: two
threads shouldn't write to the same file simultaneously, for example.
Mutexes, critical sections and semaphores can be useful for this,
depending on the circumstances.
I would look around on SourceForge, CodeProject, and CodeGuru for
projects that do similar things -- perhaps as servers -- and learn
about synchronization between threads.
Since your application is a client, it can start a thread for each
POP3 server. If the e-mails are being written to separate files, you
only need to coordinate file names between the threads; if appended to
a single mailbox thread, then the threads will have to wait for each
other to finish writing a message before beginning to write their own.
Another option would be for each receiver thread to write each message
to a temp file. An additional thread would be signaled when a file is
complete and append it to the inbox.
I hope this helps and gives you some ideas.
--
Sev
Severian - 16 Mar 2005 19:36 GMT
I have corrected several typos in my response below. Then I must go do
some real work until my brain starts working properly again!
>>Hi
>>I have written a program which receives mails from server using POP3.
>>it's downloading sequentially. now i want to use the multithreading
>>in this regard where i can create threads for each and every
>>mail...and download those mails simaltaneously.
>>if u have any idea please help me out.
(I am assuming you are downloading from multiple servers
simultaneously, and not trying to download a bunch of messages from a
single account; I don't believe POP3 even supports the latter)
First, be careful *not* to share resources without synchronization:
two threads shouldn't write to the same file simultaneously, for
example. Mutexes, critical sections and semaphores can be useful for
this, depending on the circumstances.
I would look around on SourceForge, CodeProject, and CodeGuru for
projects that do similar things -- perhaps as servers -- and learn
about synchronization between threads.
Since your application is a client, it can start a thread for each
POP3 server. If the e-mails are being written to separate files, you
only need to coordinate file names between the threads; if appended to
a single mailbox *file*, then the threads will have to wait for each
other to finish writing a message before beginning to write their own.
Another option would be for each receiver thread to write each message
to a temp file. An additional thread would be signaled when a file is
complete and append it to the inbox.
I hope this helps and gives you some ideas.
--
Sev
> Hi
> I have written a program which receives mails from server using POP3.
> it's downloading sequentially. now i want to use the multithreading
> in this regard where i can create threads for each and every
> mail...and download those mails simaltaneously.
> if u have any idea please help me out.
Idea about what? At first, opening a connection for each email
separately doesn't sound good, first because it would increase the load
on server, and second because it may look like a password attack and I
do not know if all servers will allow many connections from the same
address (mine wouldn't). :-)
Severian - 16 Mar 2005 19:34 GMT
>> Hi
>> I have written a program which receives mails from server using POP3.
[quoted text clipped - 8 lines]
>do not know if all servers will allow many connections from the same
>address (mine wouldn't). :-)
I assumed he meant different POP3 servers or at least accounts (I use
3 servers and 5 accounts). I don't think the POP3 protocol even allows
multiple connections to the same account.
--
Sev