'Download 완료 확인'에 해당되는 글 1건

  1. 2010.01.08 Semaphore 이용환 Download 완료 확인

Semaphore 이용환 Download 완료 확인

CS/Common 2010. 1. 8. 07:10
원문 : Stanford iTunesU Programming Paradigm 17강

int DownloadSingleFile(const char* server, const char* path);
int DownloadAllFiles(const char* server, const char* files[], int n)
{
	int totalBytes = 0;

	Semaphore lock = 1;
	Semaphore childrenDone = 0;

	for (int i=0; i < n; ++i)
	{
		ThreadNew("DownloadSingleFile", DownloadSingleFile, 4, server, files[i], &
		totalBytes, lock, childrenDone);
	}
	for (int i=0; i < n; ++i)
	{
		// wait return.
		SemaphoreWait(childrenDone);
	}

	return totalBytes;
}

void DownloadHelper(const char* server, const char* path, 
	int* returnButes, Semaphore lock, Semaphore parentToSignal)
{
	int bytesDownloaded = DownloadSingleFile(server, path);
	SemaphoreWait(lock);
	*numBytes += bytesDownloaded;
	SemaphoreSignal(lock);
	SemaphoreSignal(parentToSignal);
}
: